From 357e98b8db46facd4db286849fdc24ec757000fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 14 May 2023 14:04:42 +0200 Subject: [PATCH] improve logging setup --- log_setup/__init__.py | 3 +++ log_setup/logger_setup.py | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 log_setup/__init__.py diff --git a/log_setup/__init__.py b/log_setup/__init__.py new file mode 100644 index 0000000..fb1f12a --- /dev/null +++ b/log_setup/__init__.py @@ -0,0 +1,3 @@ +from .logger_setup import make_logger + +logger = make_logger() diff --git a/log_setup/logger_setup.py b/log_setup/logger_setup.py index 4dbdfb3..25a3737 100644 --- a/log_setup/logger_setup.py +++ b/log_setup/logger_setup.py @@ -1,10 +1,20 @@ import logging -logger = logging.getLogger("HANAB") +def make_logger(): + logger = logging.getLogger("hanab-suite") -logger.setLevel(logging.DEBUG) + logger.setLevel(logging.DEBUG) -handler = logging.FileHandler("log.txt") + f_handler = logging.FileHandler("a_log.txt") + f_formatter = logging.Formatter( + '[%(asctime)s] [%(name)s] [%(levelname)s]: %(message)s' + ) + f_handler.setFormatter(f_formatter) + logger.addHandler(f_handler) -logger.addHandler(handler) + console_handler = logging.StreamHandler() + console_handler.setLevel(logging.INFO) + logger.addHandler(console_handler) + + return logger