Delegate logger methods to central log() and log init errors

Refactor AzLogsLogger instance methods (debug/info/warn/error/exception) and the module-level helper functions to call the central logger.log(...) with the appropriate LogLevel, and ensure exception() passes exc_info=True. Also add a standard library logger in core/log_system/log_funcs.py and emit an error if importing the custom logger fails to aid diagnosis.
This commit is contained in:
Dariusz L
2026-04-22 03:28:40 +02:00
parent 236ca180e9
commit 5fa6b2a731
2 changed files with 15 additions and 1 deletions
+5 -1
View File
@@ -7,6 +7,9 @@
import os
import traceback
import logging
_logger = logging.getLogger(__name__)
try:
from .logger import logger, LogLevel, debug, info, warn, error, exception
@@ -28,8 +31,9 @@ try:
)
_initialized = True
except ImportError:
except ImportError as e:
_initialized = False
_logger.error(f"Failed to initialize logger: {e}")
def log_debug(*args, **kwargs):
+10
View File
@@ -276,18 +276,23 @@ class AzLogsLogger:
def debug(self, module, *args, **kwargs):
"""Log at DEBUG level"""
self.log(module, LogLevel.DEBUG, *args, **kwargs)
def info(self, module, *args, **kwargs):
"""Log at INFO level"""
self.log(module, LogLevel.INFO, *args, **kwargs)
def warn(self, module, *args, **kwargs):
"""Log at WARN level"""
self.log(module, LogLevel.WARN, *args, **kwargs)
def error(self, module, *args, **kwargs):
"""Log at ERROR level"""
self.log(module, LogLevel.ERROR, *args, **kwargs)
def exception(self, module, *args):
"""Log exception at ERROR level"""
self.log(module, LogLevel.ERROR, *args, exc_info=True)
# Singleton
@@ -297,22 +302,27 @@ logger = AzLogsLogger()
# Helper functions
def debug(module, *args, **kwargs):
"""Log at DEBUG level"""
logger.log(module, LogLevel.DEBUG, *args, **kwargs)
def info(module, *args, **kwargs):
"""Log at INFO level"""
logger.log(module, LogLevel.INFO, *args, **kwargs)
def warn(module, *args, **kwargs):
"""Log at WARN level"""
logger.log(module, LogLevel.WARN, *args, **kwargs)
def error(module, *args, **kwargs):
"""Log at ERROR level"""
logger.log(module, LogLevel.ERROR, *args, **kwargs)
def exception(module, *args):
"""Log exception at ERROR level"""
logger.log(module, LogLevel.ERROR, *args, exc_info=True)
# Function to quickly enable/disable debugging