CORD-2190: Use logger named 'multistructlog' instead of the default
logger
Change-Id: I70fcfb27011a91902b544514b36db6a5550d73e1
diff --git a/multistructlog.py b/multistructlog.py
index bf0a27f..625b275 100644
--- a/multistructlog.py
+++ b/multistructlog.py
@@ -138,19 +138,25 @@
structlog.stdlib.ProcessorFormatter.wrap_for_formatter
])
- caller = inspect.stack()[1]
- filename = inspect.getmodule(caller[0]).__name__
+
+ handlers = logging.getLogger('multistructlog').handlers
- default_handlers = [
- logging.StreamHandler(sys.stdout),
- logging.handlers.RotatingFileHandler(
- filename=filename,
- maxBytes=10485760,
- backupCount=1)
- ]
+ if not handlers:
+ caller = inspect.stack()[1]
- configured_handlers = logging.getLogger().handlers
- handlers = configured_handlers if configured_handlers else default_handlers
+ try:
+ filename = inspect.getmodule(caller[0]).__name__
+ except AttributeError:
+ filename = '/tmp/multistructlog'
+
+ handlers = [
+ logging.StreamHandler(sys.stdout),
+ logging.handlers.RotatingFileHandler(
+ filename=filename,
+ maxBytes=10485760,
+ backupCount=1)
+ ]
+
factory = XOSLoggerFactory(handlers)
structlog.configure(