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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ENV=LOCAL
# DEBUG=false
# TZ=UTC

# BEANS_LOGGING_AUTO_LEVEL=INFO
# BEANS_LOGGING_AUTO_COLORIZED=true
# BEANS_LOGGING_AUTO_FORMAT="[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{extra[level_short]:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ logger:
# ENV=LOCAL
# DEBUG=false
# TZ=UTC
# BEANS_LOGGING_AUTO_LEVEL=INFO
# BEANS_LOGGING_AUTO_COLORIZED=true
# BEANS_LOGGING_AUTO_FORMAT="[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{extra[level_short]:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>"
```

---
Expand Down
6 changes: 5 additions & 1 deletion src/beans_logging/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from potato_util import validator

_level = os.environ.get("BEANS_LOGGING_AUTO_LEVEL")
_is_colorized = validator.is_truthy(
os.environ.get("BEANS_LOGGING_AUTO_COLORIZED", "True")
)
Expand All @@ -14,14 +15,17 @@
from .constants import DEFAULT_STD_HANDLER_NAME

_kwargs: dict[str, Any] = {"auto_load": True}
_handler_config: dict[str, Any] = {}

_handler_config: dict[str, Any] = {}
if not _is_colorized:
_handler_config["colorize"] = False

if _format:
_handler_config["format_"] = _format

if _level:
_handler_config["level"] = _level

if _handler_config:
_kwargs["config"] = {"handlers": {DEFAULT_STD_HANDLER_NAME: _handler_config}}

Expand Down