From d69b24e3b58773b94d031394996c2ded457c0870 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 27 Jul 2025 15:47:20 +0200 Subject: [PATCH] make *_logging_config independent from config.py --- __init__.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index 3975bb3..0326d3d 100644 --- a/__init__.py +++ b/__init__.py @@ -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()