aboutsummaryrefslogtreecommitdiff
path: root/plip/basic/logger.py
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2020-07-02 20:48:33 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2020-07-02 20:48:33 +0530
commit4be08f7bdd77991e9e453c1cda863c3f20c338d5 (patch)
tree083e8e91622221185a28fd50754abc2f86b1df43 /plip/basic/logger.py
initial commit
Diffstat (limited to 'plip/basic/logger.py')
-rw-r--r--plip/basic/logger.py21
1 files changed, 21 insertions, 0 deletions
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