diff --git a/README.md b/README.md index 2a7b8ac..114bd75 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ [![Discord](https://img.shields.io/badge/Discord-Support%20Server-7289DA?style=flat&logo=discord)](https://discord.gg/Ms2ejEES) What is VersaLog.py? -VersaLog is a powerful and flexible logging library for Python. -It supports everything from simple usage to advanced, highly customizable configurations to meet a wide range of needs. + +VersaLog is a modern, powerful, and flexible logging library for Python. +It supports everything from simple usage to advanced, highly customizable configurations, making it suitable for a wide range of use cases. ## Feature diff --git a/VersaLog/__init__.py b/VersaLog/__init__.py index 9397fa4..c965e2f 100644 --- a/VersaLog/__init__.py +++ b/VersaLog/__init__.py @@ -1,10 +1,13 @@ from .core import VersaLog from .handler import VersaLogHandler +from .integrations.auto import auto_setup from .integrations.fastapi import setup_fastapi_logging +from .integrations.flask import setup_flask_logging +from .integrations.django import setup_django_logging __copyright__ = "Copyright 2025 by Kayu0514" -__version__ = "2.5.6" +__version__ = "2.6.0" __author__ = "Kayu0514" __url__ = "https://github.com/kayu0514" -__all__ = ["VersaLog", "VersaLogHandler", "setup_fastapi_logging"] \ No newline at end of file +__all__ = ["VersaLog", "VersaLogHandler", "auto_setup", "setup_fastapi_logging","setup_flask_logging", "setup_django_logging"] \ No newline at end of file diff --git a/VersaLog/integrations/auto.py b/VersaLog/integrations/auto.py new file mode 100644 index 0000000..d343036 --- /dev/null +++ b/VersaLog/integrations/auto.py @@ -0,0 +1,32 @@ +import sys + +from .generic import setup_logging +from .fastapi import setup_fastapi_logging +from .flask import setup_flask_logging +from .django import setup_django_logging + + +def auto_setup(versalog): + """ + Automatically detects the runtime environment + and applies the appropriate logging configuration. + """ + + if "uvicorn" in sys.modules: + setup_fastapi_logging(versalog) + return "fastapi" + + if "gunicorn" in sys.modules: + setup_fastapi_logging(versalog) + return "gunicorn" + + if "flask" in sys.modules: + setup_flask_logging(None, versalog) + return "flask" + + if "django" in sys.modules: + setup_django_logging(versalog) + return "django" + + setup_logging(versalog) + return "generic" \ No newline at end of file diff --git a/VersaLog/integrations/django.py b/VersaLog/integrations/django.py new file mode 100644 index 0000000..8ae378c --- /dev/null +++ b/VersaLog/integrations/django.py @@ -0,0 +1,5 @@ +from .generic import setup_logging + + +def setup_django_logging(versalog): + setup_logging(versalog) \ No newline at end of file diff --git a/VersaLog/integrations/flask.py b/VersaLog/integrations/flask.py new file mode 100644 index 0000000..de54406 --- /dev/null +++ b/VersaLog/integrations/flask.py @@ -0,0 +1,8 @@ +from .generic import setup_logging + + +def setup_flask_logging(app, versalog): + setup_logging(versalog) + + app.logger.handlers.clear() + app.logger.propagate = True \ No newline at end of file diff --git a/VersaLog/integrations/generic.py b/VersaLog/integrations/generic.py new file mode 100644 index 0000000..3ffffb8 --- /dev/null +++ b/VersaLog/integrations/generic.py @@ -0,0 +1,14 @@ +import logging +from ..handler import VersaLogHandler + + +def setup_logging(versalog): + handler = VersaLogHandler(versalog) + + root = logging.getLogger() + + for h in root.handlers[:]: + root.removeHandler(h) + + root.setLevel(logging.NOTSET) + root.addHandler(handler) \ No newline at end of file diff --git a/setup.py b/setup.py index 766e7d1..2894b2d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="VersaLog", - version="2.5.6", + version="2.6.0", description="Versatile logging library.", long_description=long_description, long_description_content_type="text/markdown",