feat: Enhance logging configuration and add dynamic log level support
This commit is contained in:
+2
-1
@@ -61,7 +61,8 @@ class ServerConfig:
|
||||
self.schedule_weekly_days = config.get("schedule_weekly_days", [0])
|
||||
self.schedule_weekly_time = config.get("schedule_weekly_time", "03:00")
|
||||
self.schedule_auto_watch = config.get("schedule_auto_watch", False)
|
||||
logger.info(f"Server config loaded: {self.__dict__}")
|
||||
logger.info(f"Server config loaded.")
|
||||
logger.debug(f"Current server config: {self.__dict__}")
|
||||
|
||||
def save(self):
|
||||
config = {
|
||||
|
||||
+23
-1
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user