diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/modellogger/log_config.py b/modellogger/log_config.py index d2207ab..5fb46db 100644 --- a/modellogger/log_config.py +++ b/modellogger/log_config.py @@ -13,13 +13,13 @@ class DefaultFormatter(logging.Formatter): "RESET": "\x1b[0m", } - def __init__(self, app_name=None, include_colors=True): + def __init__(self, app_name=".", include_colors=True): super().__init__() - if app_name is None: - app_name = __name__.split(".")[0] self.app_name = app_name self.include_colors = include_colors - self.base_format = "%(asctime)s - {app_name} - %(levelname)s - %(message)s" + self.base_format = ( + "%(asctime)s - {app_name} - %(name)s - %(levelname)s - %(message)s" + ) def format(self, record): date_format = "%Y-%m-%dT%H:%M:%SZ" @@ -34,7 +34,7 @@ def format(self, record): return formatter.format(record) -def get_logger(name, app_name=None, level=logging.INFO, log_file=None): +def get_logger(name, app_name=".", level=logging.INFO, log_file=None): logger = logging.getLogger(name) logger.handlers.clear() @@ -56,9 +56,7 @@ def get_logger(name, app_name=None, level=logging.INFO, log_file=None): return logger -def get_config_dict(app_name=None, log_file=None): - if app_name is None: - app_name = __name__.split(".")[0] +def get_config_dict(app_name=".", log_file=None): config = { "version": 1, "disable_existing_loggers": False, diff --git a/tests/test_log_config.py b/tests/test_log_config.py index 88409d9..6b0278c 100644 --- a/tests/test_log_config.py +++ b/tests/test_log_config.py @@ -84,8 +84,8 @@ def test_default_formatter_app_name_default(monkeypatch): # Patch the __name__ attribute using the imported module monkeypatch.setattr(log_config, "__name__", "mypackage.submodule") formatter = DefaultFormatter() - assert formatter.app_name == "mypackage" + assert formatter.app_name == "." monkeypatch.setattr(log_config, "__name__", "mymodule") formatter = DefaultFormatter() - assert formatter.app_name == "mymodule" + assert formatter.app_name == "."