Skip to content

Commit e9fa8c2

Browse files
Don't set file output in root logger
1 parent f2cbec3 commit e9fa8c2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

_delphi_utils_python/delphi_utils/logger.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ def get_structured_logger(name=__name__,
4040
is a good choice.
4141
filename: An (optional) file to write log output.
4242
"""
43-
# Configure the underlying logging configuration
44-
handlers = [logging.StreamHandler()]
45-
if filename:
46-
handlers.append(logging.FileHandler(filename))
47-
43+
# Configure the basic underlying logging configuration
4844
logging.basicConfig(
4945
format="%(message)s",
5046
level=logging.INFO,
51-
handlers=handlers
52-
)
47+
handlers=[logging.StreamHandler()]
48+
)
5349

5450
# Configure structlog. This uses many of the standard suggestions from
5551
# the structlog documentation.
@@ -84,7 +80,12 @@ def get_structured_logger(name=__name__,
8480
cache_logger_on_first_use=True,
8581
)
8682

87-
logger = structlog.get_logger(name)
83+
# Create the underlying python logger and wrap it with structlog
84+
system_logger = logging.getLogger(name)
85+
if filename:
86+
system_logger.addHandler(logging.FileHandler(filename))
87+
system_logger.setLevel(logging.INFO)
88+
logger = structlog.wrap_logger(system_logger)
8889

8990
if log_exceptions:
9091
handle_exceptions(logger)

0 commit comments

Comments
 (0)