aboutsummaryrefslogtreecommitdiff
path: root/rumba/log.py
diff options
context:
space:
mode:
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