Skip to content

Commit 8ee933e

Browse files
committed
add testing environment indicator to the logger
1 parent 51f0814 commit 8ee933e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

_delphi_utils_python/delphi_utils/logger.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def threading_exception_handler(args):
4444
threading.excepthook = threading_exception_handler
4545

4646

47-
def get_structured_logger(name=__name__, filename=None, log_exceptions=True):
47+
def get_structured_logger(name=__name__, filename=None, log_exceptions=True, is_real=True):
4848
"""Create a new structlog logger.
4949
5050
Use the logger returned from this in indicator code using the standard
@@ -63,6 +63,9 @@ def get_structured_logger(name=__name__, filename=None, log_exceptions=True):
6363
name: Name to use for logger (included in log lines), __name__ from caller
6464
is a good choice.
6565
filename: An (optional) file to write log output.
66+
log_exceptions: should we log exceptions?
67+
is_real: is this logger *not* in a testing environment? Used to avoid
68+
setting features that interfere with testing the logging output
6669
"""
6770
# Set the underlying logging configuration
6871
if "LOG_DEBUG" in os.environ:
@@ -109,7 +112,7 @@ def add_pid(_logger, _method_name, event_dict):
109112
# Use a standard wrapper class for utilities like log.warning()
110113
wrapper_class=structlog.stdlib.BoundLogger,
111114
# Cache the logger
112-
cache_logger_on_first_use=True,
115+
cache_logger_on_first_use=is_real,
113116
)
114117

115118
# Create the underlying python logger and wrap it with structlog

0 commit comments

Comments
 (0)