-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix configuring loggers found in 'PREFECT_LOGGING_EXTRA_LOGGERS' #16652
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
zzstoatzz
merged 1 commit into
PrefectHQ:main
from
estasney:fix-configuring-extra-loggers
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it not work if this code were changed to:
handler.setLevel(extra_config.level)instead oflogger.setLevel(extra_config.level)?Again, my motivation on creating the original issue is that non-prefect libraries may not know about the "extra_config.level" parameter and may have other mechanisms for setting up their own logging config. IMO, Prefect's handler should be more like an add on not a replacement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets assume we're using the logging.yml prefect uses. I'm also assuming non-prefect libraries follow the logging guidelines (IME most do) Python Logging
A library will typically do
If I run a flow, I'll see the warning in the prefect ui, but not the debug.
debug > notset. Assuming above, the libraries logger does not have its level set and defers to the root logger (warning).What I'm proposing won't interfere with libraries logging config. It will only adjust how the user (us) receive them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what if the handler set up by prefect isn't the only handler?
This issue came about because my library can create two handlers -- one at level debug to write to a log file and one at level warning to write to the console.
So for logger = logging.getLogger("myLib")
logger.debug - goes to one handler
logger.warning - matches two handlers
I was trying to make my prefect UI logger match what my console logger does today. The way I achieve that right now is:
logger.setLevel('debug')
for each handler in logger.getHandlers(), search for prefect's handler
handler.addFilter(my_filter_function)
where my_filter_function does not forward the debug level stuff up to the UI
This hack is dependent on the order in which library imports happen - because the parent level logger could be set by prefect or by my library depending on who's initializer runs first.
In my opinion, the prefect "extra logging level" should configure only prefect's handler object, not to the entire logger object.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @estasney and @j-carson for articulating your positions!
After chatting a bit with @desertaxle, we agree we're doing the wrong thing by modifying external loggers' levels. We should probably only configure our own handlers:
This would technically be a breaking change but it's arguably more correct - we should only configure our own handlers, not override library logging levels.
What do you think @estasney? (sounds like this is what you were opting for @j-carson - feel free to correct me)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a side note, please use
pre-commit installbefore your next commit to avoid the static analysis errorshttps://docs.prefect.io/contribute/dev-contribute#install-prefect-for-development
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@j-carson I see your point, and this is an interesting problem. I suppose my perspective was more geared towards favoring logging logic being defined in the deployment vs in code. I will remove the bit about setting external loggers.
@zzstoatzz Thanks for reviewing! Just want to point out that
May appear to cause side effects
But would effectively become (after running
setup_logging)If the goal is not to modify the level of external loggers should we also extend that to the propagate property? I.e. don't modify external loggers propagate
Sorry I missed the pre-commit install I'll fix that now
I'll move this a draft PR as I also want to add a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zzstoatzz Yes, this is what I was asking for