diff options
author | Marco Capitani <m.capitani@nextworks.it> | 2017-04-21 16:56:03 +0200 |
---|---|---|
committer | Marco Capitani <m.capitani@nextworks.it> | 2017-04-21 16:56:03 +0200 |
commit | 18836a44952929a47f5f65d93667472816e9eb8f (patch) | |
tree | 2fb8a9f65a77457adf4dd4a0a79ffd498f87fa02 /rumba/log.py | |
parent | 2da2f7f095dd985e6beb57be4b239f3b0eb87973 (diff) | |
download | rumba-18836a44952929a47f5f65d93667472816e9eb8f.tar.gz rumba-18836a44952929a47f5f65d93667472816e9eb8f.zip |
rumba: log: Simplified configuration, small fixes
Diffstat (limited to 'rumba/log.py')
-rw-r--r-- | rumba/log.py | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/rumba/log.py b/rumba/log.py index c9c3c01..ebb76dc 100644 --- a/rumba/log.py +++ b/rumba/log.py @@ -5,46 +5,35 @@ import sys import multiprocessing -config_lock = multiprocessing.Lock() +def setup(): + 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) -class _LoggingConfigurator(object): +# Used for the first call, in order to configure logging +def _get_logger_with_setup(name): + setup() + # Swap _get_logger implementation to the setup-less version. + global _get_logger + _get_logger = _get_logger_without_setup + return logging.getLogger(name) - 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 +# Then this one is used. +def _get_logger_without_setup(name): + return logging.getLogger(name) - 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() +_get_logger = _get_logger_with_setup def get_logger(name): - logger = configurator.get_logger(name.split('.')[-1]) + logger = _get_logger(name.split('.')[-1]) logger.setLevel(logging.DEBUG) return logger |