-
Notifications
You must be signed in to change notification settings - Fork 52
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
pycromanager setting the root logger on import #766
Comments
Suggestions on a PR for a fix? Any thoughts on this @jacopoabramo ? |
Depends on where the break came from, but it looks like this commit to PyJavaZ For one, this introduces a circular import dependency, so I would be a bit careful here, but the most likely fix is to just remove this line: |
(on the other hand, it looks like that commit also introduced a lot of usage of I have a lot of experience with Python logging, if you have a list of requirements (importing module X should trigger logging at level Y, but by default logging should be at level Z, but only for modules ABC, etc.), happy to send a PR, but it's a bit hard to infer from the current state what the original intention was! |
Yeah the circular dependency is definitely not supposed to be there and should be removed. I don't think that any special logging is required in PyJavaZ, so that could all be removed. All this logging was added in #719 |
Hey, sorry for the late reply. I'm the author of PR #719 Background on this PR is: I wanted to add a logger instance for debugging to be compatible with another project I've been working on (integrating pycromanager in ImSwitch). I have to admit I'm not an expert on logging and my initial thought was the following: creating a logger instance that would be the baseline for debugging when @bruno-digitbio I would happy to provide a fixing PR if you have some suggestions on how to approach this |
Hi all - This is a high priority issue for us as well, as the changes are creating chaos with logging and the console. Is there anything we can do to help push forward fixing the problem? Thanks. |
Are you trying to use (in coloredlogs.install(
level='DEBUG',
logger=logging.getLogger("pycromanager"),
fmt='%(asctime)s %(levelname)s %(message)s'
) after this point, any code that logs to the
I think I see what you were trying to do here, definitely a reasonable thought, but (if I'm understanding correctly), simply coming from the wrong mental model for how Python's built-in
Walking through the implications of the system I (try to) outline above, if you want to apply the same logger configuration used by (e.g.) If you want to "reset" the settings back to normal, you should again definitely not replace the logger object itself, but instead you should modify it's (global) properties to have the settings that you want. For example, In [2]: import logging
In [3]: pycro_logger = logging.getLogger("pycromanager")
In [4]: import coloredlogs
In [5]: coloredlogs.install(logger=pycro_logger, level=logging.DEBUG)
In [6]: pycro_logger.handlers
Out[6]: [<StandardErrorHandler <stderr> (INFO)>] so to undo that, you would just remove it and reset the In [11]: pycro_logger.setLevel(logging.WARNING)
In [12]: pycro_logger.removeHandler(pycro_logger.handlers[0])
In [13]: pycro_logger.handlers
Out[13]: []
There's a few things to fix here, across a couple of repositories:
|
@dpshepherd, In the mean time, at work we are patching this problem by making sure that (something like) the following lines are executed before any other imports: import pycromanager.logging # trigger the "bad" `logging.basicConfig` call
import logging
logging.getLogger().handlers = [] # delete the erroneously-created handler after this, stuff like import numba no longer creates walls of output |
This removes public API (first introduced in micro-manager#719) for bypassing Python's internal logging system by creating and caching a logger instance in place of using `logging.getLogger("pycromanager")`. Users of that previous API---i.e., application code authors that want to globally control logging and users that want to customize Pycromanager's logging outputs---are encouraged to simply directly use the logging module to affect these changes instead. See micro-manager#766 for discussion.
This removes public API (first introduced in micro-manager#719) for bypassing Python's internal logging system by creating and caching a logger instance in place of using `logging.getLogger("pycromanager")`. Users of that previous API---i.e., application code authors that want to globally control logging and users that want to customize Pycromanager's logging outputs---are encouraged to simply directly use the logging module to affect these changes instead. See micro-manager#766 for discussion.
This removes public API (first introduced in micro-manager#719) for bypassing Python's internal logging system by creating and caching a logger instance in place of using `logging.getLogger("pycromanager")`. Users of that previous API---i.e., application code authors that want to globally control logging and users that want to customize Pycromanager's logging outputs---are encouraged to simply directly use the logging module to affect these changes instead. See micro-manager#766 for discussion.
Code for reproduction / Actual Outcome
The latest version of
pycromanager
adds an error handler that forwards all logging messages from the root logger to stdout. Resulting in a wall of DEBUG messages when loading any module (e.g.matplotlib
,numba
, etc.) that uses thelogging
module extensively.Expected outcome
Only deployed binaries should set the root logger. Libraries that are meant to be imported by others should leave it untouched.
The offending code is here.
If we really want to always print debug messages for
pycromanager
specifically, you can of course set this configuration forpycromanager
's internal logger instead:The text was updated successfully, but these errors were encountered: