From 4be08f7bdd77991e9e453c1cda863c3f20c338d5 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Thu, 2 Jul 2020 20:48:33 +0530 Subject: initial commit --- plip/basic/logger.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 plip/basic/logger.py (limited to 'plip/basic/logger.py') diff --git a/plip/basic/logger.py b/plip/basic/logger.py new file mode 100644 index 0000000..ca65411 --- /dev/null +++ b/plip/basic/logger.py @@ -0,0 +1,21 @@ +import inspect +import logging + + +def get_logger(): + """ + Configures a base logger and returns a module-specific sub-logger of the calling module. + """ + frame = inspect.stack()[1] + module_name = inspect.getmodule(frame[0]).__name__ + if module_name != '__main__': + logger = logging.getLogger(module_name) + if not logger.parent.handlers: + ch = logging.StreamHandler() + formatter = logging.Formatter('%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(name)s: %(message)s') + ch.setFormatter(formatter) + logger.parent.addHandler(ch) + else: + logger = logging.getLogger('plip') + + return logger -- cgit v1.2.3