Skip to content

Allow multiple logger configs #980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions _delphi_utils_python/delphi_utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down