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.
73 lines
1.5 KiB
Python
73 lines
1.5 KiB
Python
"""
|
|
@author: Azornes
|
|
@title: AzLogs
|
|
@version: 1.4.0
|
|
@description: Logging Initializator
|
|
"""
|
|
|
|
import os
|
|
import traceback
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
try:
|
|
from .logger import logger, LogLevel, debug, info, warn, error, exception
|
|
from .config import LOG_LEVEL, LOG_MODULE_NAME
|
|
|
|
_module_name = (
|
|
LOG_MODULE_NAME
|
|
if LOG_MODULE_NAME is not None
|
|
else os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
|
)
|
|
|
|
logger.set_module_level(_module_name, LogLevel[LOG_LEVEL])
|
|
|
|
logger.configure(
|
|
{
|
|
"log_to_file": True,
|
|
"log_dir": os.path.join(os.path.dirname(os.path.abspath(__file__)), "logs"),
|
|
}
|
|
)
|
|
|
|
_initialized = True
|
|
except ImportError as e:
|
|
_initialized = False
|
|
_logger.error(f"Failed to initialize logger: {e}")
|
|
|
|
|
|
def log_debug(*args, **kwargs):
|
|
if _initialized:
|
|
debug(_module_name, *args, **kwargs)
|
|
else:
|
|
print("[DEBUG]", *args)
|
|
|
|
|
|
def log_info(*args, **kwargs):
|
|
if _initialized:
|
|
info(_module_name, *args, **kwargs)
|
|
else:
|
|
print("[INFO]", *args)
|
|
|
|
|
|
def log_warn(*args, **kwargs):
|
|
if _initialized:
|
|
warn(_module_name, *args, **kwargs)
|
|
else:
|
|
print("[WARN]", *args)
|
|
|
|
|
|
def log_error(*args, **kwargs):
|
|
if _initialized:
|
|
error(_module_name, *args, **kwargs)
|
|
else:
|
|
print("[ERROR]", *args)
|
|
|
|
|
|
def log_exception(*args):
|
|
if _initialized:
|
|
exception(_module_name, *args)
|
|
else:
|
|
print("[ERROR]", *args)
|
|
traceback.print_exc()
|