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
Sentry uses logging's levelname instead of levelno when mapping to levels. #1443
Comments
This might just need to have a warning in the docs that sentry expects you not to override your level names, and that doing so can break sentry level reporting (although changing the names to lower case is handled ok.) My work around was to no longer modify the levelname in my logging setup, but rather to make a custom formatter that dynamically changes the formatting based on the level, per https://stackoverflow.com/questions/1343227/can-pythons-logging-format-be-modified-depending-on-the-message-log-level But I also wonder if the project wants to consider using |
The code in question is:
I would like to suggest that a more correct implementation would be something like:
|
Hey @rrauenza ! Thanks for bringing this up! I agree matching the event name with the log level instead number instead of the log level name is way more robust. If you provide a PR than I am happy to review and merge it! |
Is 'error' the default we want to use if the levelno is unknown?
...before, if the levelname was 'foo' we would just post to sentry with 'foo' and complain. |
Good question. I think we should not change the behavior in case the log level name is unknown. (Because we would probably break users existing code) So if the level can not be matched the lower case level name should be used (as it is now) |
@antonpirker PR has been updated. |
How do you use Sentry?
Self-hosted/on-premise
Version
1.5.12
Steps to Reproduce
Where I work, it has been a convention to do the following in order to get python logging to modify its output to be a little cleaner:
This along with:
This causes a sentry error that the level name of
warning:
doesn't exist. Probably because sentry sdk is mapping to sentry levels using levelname of the log message and not levelno.Expected Result
Sentry should map from the logging level correctly.
Actual Result
I get an invalid level name of 'warning:' in the sentry record in the GUI.
I'll include my work around below in further comment.
The text was updated successfully, but these errors were encountered: