склади и инструмент готовы
This commit is contained in:
+17
-4
@@ -1,10 +1,20 @@
|
||||
import logging
|
||||
import logging.config
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class SmartLogger(logging.Logger):
|
||||
def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, stacklevel=2):
|
||||
def _log(
|
||||
self,
|
||||
level,
|
||||
msg,
|
||||
args,
|
||||
exc_info=None,
|
||||
extra=None,
|
||||
stack_info=False,
|
||||
stacklevel=2,
|
||||
):
|
||||
# Увеличиваем stacklevel до 2, чтобы показать реального вызывающего
|
||||
if isinstance(msg, (dict, list)):
|
||||
msg = json.dumps(msg, indent=4, ensure_ascii=False)
|
||||
@@ -12,9 +22,12 @@ class SmartLogger(logging.Logger):
|
||||
|
||||
|
||||
logging.setLoggerClass(SmartLogger)
|
||||
logging.config.fileConfig("config/log.ini")
|
||||
# logging.config.fileConfig("config/log.ini")
|
||||
|
||||
logger = logging.getLogger("toolbox")
|
||||
log_config_path = Path("config/log.ini")
|
||||
logging.config.fileConfig(log_config_path, disable_existing_loggers=False)
|
||||
|
||||
|
||||
def setLogLevel(level: str = ""):
|
||||
match level:
|
||||
@@ -26,10 +39,10 @@ def setLogLevel(level: str = ""):
|
||||
loggerLevel = logging.ERROR
|
||||
case _:
|
||||
loggerLevel = logging.INFO
|
||||
|
||||
|
||||
root_logger = logging.getLogger()
|
||||
for handler in root_logger.handlers:
|
||||
handler.setLevel(loggerLevel)
|
||||
|
||||
# Также меняем уровень самого логгера
|
||||
logger.setLevel(loggerLevel)
|
||||
logger.setLevel(loggerLevel)
|
||||
|
||||
Reference in New Issue
Block a user