feat: Enhance logging configuration and add dynamic log level support

This commit is contained in:
2025-12-02 10:15:44 +09:00
parent aa4517aaf5
commit 3f43662c1f
3 changed files with 26 additions and 2 deletions
+23 -1
View File
@@ -4,7 +4,29 @@ import os
LOG_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "logs", "app.log"))
LOG_LEVEL = logging.DEBUG
def _get_log_level():
"""Get log level from environment variable."""
level_str = os.getenv("LOG_LEVEL", "INFO").upper()
# Try to convert to integer
if level_str.isdigit():
return int(level_str)
# Map string to logging level
levels = {
"CRITICAL": logging.CRITICAL,
"FATAL": logging.FATAL,
"ERROR": logging.ERROR,
"WARN": logging.WARNING,
"WARNING": logging.WARNING,
"INFO": logging.INFO,
"DEBUG": logging.DEBUG,
"NOTSET": logging.NOTSET,
}
return levels.get(level_str, logging.INFO)
LOG_LEVEL = _get_log_level()
def logger_initialize() -> logging.Logger:
"""Initialize the logger for the application. Return a logger that logs to console and a app.log."""