-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Distfit modifies the root logger globally #51
Comments
The workaround I have for this at the moment is: from contextlib import contextmanager
@contextmanager
def preserve_root_logger():
"""Preserve the root logger when executing code.
This is to stop distlib from modifying the root logger:
https://github.com/erdogant/distfit/issues/51
"""
# Save original logger state
root_logger = logging.getLogger()
original_handlers = root_logger.handlers[:]
original_level = root_logger.level
try:
yield # Allow code to run inside the context
finally:
# Restore original handlers
root_logger.handlers.clear()
for handler in original_handlers:
root_logger.addHandler(handler)
root_logger.setLevel(original_level)
with preserve_root_logger():
import distfit |
Thank you for the feedback.
I first set the logger to |
It should be version >= 1.8.2 |
Description
Importing
distfit
modifies all logs in our project, this does not happen with any other packages. This happens becausedistfit
modifies the root logger globally: https://github.com/erdogant/distfit/blob/master/distfit/distfit.py#L26Since
distfit
is a library it should at least use a local logger withlogger = logging.getLogger(__name__)
, and ideally it should not be configuring logs for its downstream applications.Minimal reproducible example
Output:
Expected behaviour
Importing distfit should not modify existing logger
The text was updated successfully, but these errors were encountered: