From 80a1b907591395df5391d7c1f411973e308a41e4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 16 Feb 2024 16:07:10 +0100 Subject: [PATCH] log.get_logger --- log/__init__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 log/__init__.py diff --git a/log/__init__.py b/log/__init__.py new file mode 100644 index 0000000..51454a9 --- /dev/null +++ b/log/__init__.py @@ -0,0 +1,22 @@ +import logging +import sys + + +def get_logger(name: str) -> logging.Logger: + formatter = logging.Formatter( + "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s" + ) + + # file_handler = logging.FileHandler('log.txt') + # file_handler.setFormatter(formatter) + # file_handler.setLevel(logging.INFO) + + out_handler = logging.StreamHandler(stream=sys.stdout) + out_handler.setFormatter(formatter) + out_handler.setLevel(logging.INFO) + + logger = logging.getLogger(name) + # logger.addHandler(file_handler) + logger.addHandler(out_handler) + logger.setLevel(logging.INFO) + return logger