make *_logging_config independent from config.py

This commit is contained in:
Dirk Alders 2025-07-27 15:47:20 +02:00
parent a10d79357e
commit d69b24e3b5

View File

@ -29,7 +29,6 @@ report (Report Module)
__DEPENDENCIES__ = []
import collections
import config
import json
import logging
from logging.config import dictConfig
@ -37,6 +36,18 @@ import logging.handlers
import os
import sys
try:
from config import DEBUG
except ImportError:
DEBUG = True
try:
from config import LOG_LEVEL
except ImportError:
LOG_LEVEL = logging.DEBUG
try:
from config import LOG_HOSTNAME
except ImportError:
LOG_HOSTNAME = 'localhost'
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
@ -205,14 +216,25 @@ def add_handler_socket(logger: logging.Logger, level: int = logging.DEBUG, host:
def app_logging_config():
"""You are able to configure logging by a config file including these line:
import logging
DEBUG = False
#
# Logging
#
LOG_HOSTNAME = "loggy" # When DEBUG is True
"""
logger = logging.getLogger(ROOT_LOGGER_NAME)
if config.DEBUG:
add_handler_socket(logger, host=config.LOG_HOSTNAME)
if DEBUG:
add_handler_socket(logger, host=LOG_HOSTNAME)
return logger.getChild('main')
def default_logging_config(fmt=JOURNAL_FMT):
"""This requires a config file with at least these line:
"""You are able to configure logging by a config file including these line:
import logging
@ -227,7 +249,7 @@ def default_logging_config(fmt=JOURNAL_FMT):
"""
logger = logging.getLogger(ROOT_LOGGER_NAME)
add_handler_stdout(logger, config.LOG_LEVEL, fmt=fmt)
add_handler_stdout(logger, LOG_LEVEL, fmt=fmt)
return app_logging_config()