Skip to content

Commit

Permalink
add testing environment indicator to the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
dsweber2 committed Aug 29, 2024
1 parent 51f0814 commit 8ee933e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions _delphi_utils_python/delphi_utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def threading_exception_handler(args):
threading.excepthook = threading_exception_handler


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

# Create the underlying python logger and wrap it with structlog
Expand Down

0 comments on commit 8ee933e

Please sign in to comment.