Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions VersaLog/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
__all__ = ["VersaLog", "VersaLogHandler", "auto_setup", "setup_fastapi_logging","setup_flask_logging", "setup_django_logging"]
32 changes: 32 additions & 0 deletions VersaLog/integrations/auto.py
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions VersaLog/integrations/django.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .generic import setup_logging


def setup_django_logging(versalog):
setup_logging(versalog)
8 changes: 8 additions & 0 deletions VersaLog/integrations/flask.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions VersaLog/integrations/generic.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading