From e9fa8c2e2d35ca4266fd9bbdbb63d111fed3e3df Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 31 Mar 2021 15:28:30 -0400 Subject: [PATCH 1/2] Don't set file output in root logger --- _delphi_utils_python/delphi_utils/logger.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/_delphi_utils_python/delphi_utils/logger.py b/_delphi_utils_python/delphi_utils/logger.py index 62f2ff460..35560114e 100644 --- a/_delphi_utils_python/delphi_utils/logger.py +++ b/_delphi_utils_python/delphi_utils/logger.py @@ -40,16 +40,12 @@ def get_structured_logger(name=__name__, is a good choice. filename: An (optional) file to write log output. """ - # Configure the underlying logging configuration - handlers = [logging.StreamHandler()] - if filename: - handlers.append(logging.FileHandler(filename)) - + # Configure the basic underlying logging configuration logging.basicConfig( format="%(message)s", level=logging.INFO, - handlers=handlers - ) + handlers=[logging.StreamHandler()] + ) # Configure structlog. This uses many of the standard suggestions from # the structlog documentation. @@ -84,7 +80,12 @@ def get_structured_logger(name=__name__, cache_logger_on_first_use=True, ) - logger = structlog.get_logger(name) + # Create the underlying python logger and wrap it with structlog + system_logger = logging.getLogger(name) + if filename: + system_logger.addHandler(logging.FileHandler(filename)) + system_logger.setLevel(logging.INFO) + logger = structlog.wrap_logger(system_logger) if log_exceptions: handle_exceptions(logger) From 3dcefe843d1ea5a20b09fb67fb86ed558cb0cc44 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 31 Mar 2021 15:34:35 -0400 Subject: [PATCH 2/2] Whitespace --- _delphi_utils_python/delphi_utils/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_delphi_utils_python/delphi_utils/logger.py b/_delphi_utils_python/delphi_utils/logger.py index 35560114e..0b7a58032 100644 --- a/_delphi_utils_python/delphi_utils/logger.py +++ b/_delphi_utils_python/delphi_utils/logger.py @@ -45,7 +45,7 @@ def get_structured_logger(name=__name__, format="%(message)s", level=logging.INFO, handlers=[logging.StreamHandler()] - ) + ) # Configure structlog. This uses many of the standard suggestions from # the structlog documentation.