Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

backend/log: fix setup_logging() for multiple invocations

Also, add named NullHandler to root logger; otherwise I saw some
packages that will accidentally think our logging subsystem isn't
configured and will try to configure it with their defaults.
  • Loading branch information...
commit ead69a676360bbfa9c2a8a984211d026e80b61cd 1 parent b02f6a4
@yaniv-aknin yaniv-aknin authored
Showing with 10 additions and 3 deletions.
  1. +10 −3 config/log.py
View
13 config/log.py
@@ -28,9 +28,13 @@ def filter(self, record):
return True
def setup_logging(*roots, **kwargs):
- if hasattr(setup_logging, 'done'):
- return
- setup_logging.done = True
+ if not hasattr(setup_logging, 'configured_roots'):
+ setup_logging.configured_roots = set()
+ configured_roots = setup_logging.configured_roots
+ if not configured_roots: # first invocation
+ null_handler = logging.NullHandler()
+ null_handler.set_name('null')
+ logging.getLogger().addHandler(null_handler)
level = kwargs.pop('level', logging.DEBUG)
formatter = logging.Formatter('[%(process)05d/%(threadName)-10s] [%(levelno)02d] %(context_id)s '
'%(name)-12s %(message)s')
@@ -38,6 +42,9 @@ def setup_logging(*roots, **kwargs):
handler.setFormatter(formatter)
handler.addFilter(ContextFilter())
for root_name in {'jj'}.union(roots):
+ if root_name in configured_roots:
+ continue
+ configured_roots.add(root_name)
logger = logging.getLogger(root_name)
logger.addHandler(handler)
logger.setLevel(level)
Please sign in to comment.
Something went wrong with that request. Please try again.