aboutsummaryrefslogtreecommitdiff
path: root/rumba/log.py
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2017-04-21 15:58:56 +0200
committerMarco Capitani <m.capitani@nextworks.it>2017-04-21 15:58:56 +0200
commit26e3e22cd6ca6676b7b99624764f8e6f1ae1479d (patch)
tree65764b5ce423dc88a318e3b7325281bf3a094070 /rumba/log.py
parentee2f6e5c21c0ba94048dbf1c86024e3181718fc2 (diff)
downloadrumba-26e3e22cd6ca6676b7b99624764f8e6f1ae1479d.tar.gz
rumba-26e3e22cd6ca6676b7b99624764f8e6f1ae1479d.zip
rumba: log: Added logging support, migrated from print to logging.
+ Added logging, migrated, default logging configuration is to stdout. + Minor PEP8 adjustments all-around
Diffstat (limited to 'rumba/log.py')
-rw-r--r--rumba/log.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/rumba/log.py b/rumba/log.py
new file mode 100644
index 0000000..c9c3c01
--- /dev/null
+++ b/rumba/log.py
@@ -0,0 +1,50 @@
+import logging
+
+import sys
+
+import multiprocessing
+
+
+config_lock = multiprocessing.Lock()
+
+
+class _LoggingConfigurator(object):
+
+ is_done = False
+
+ def setup(self):
+ with config_lock:
+ if not self.is_done:
+ # Double check, so we only configure once.
+ handler = logging.StreamHandler(sys.stdout)
+ handler.lock = multiprocessing.RLock()
+ logging.basicConfig(format='{asctime} | {levelname:8.8} | '
+ '{name:15.15} | {message}',
+ style='{',
+ handlers=[handler],
+ level=logging.DEBUG)
+ logging.getLogger('').setLevel(logging.ERROR)
+ global configurator
+ configurator = _SkipLoggingConfigurator()
+ else:
+ pass
+
+ def get_logger(self, name):
+ self.setup()
+ return logging.getLogger(name)
+
+
+class _SkipLoggingConfigurator(object):
+
+ @staticmethod
+ def get_logger(name):
+ return logging.getLogger(name)
+
+
+configurator = _LoggingConfigurator()
+
+
+def get_logger(name):
+ logger = configurator.get_logger(name.split('.')[-1])
+ logger.setLevel(logging.DEBUG)
+ return logger