Sentry uses logging's levelname instead of levelno when mapping to levels.
See original GitHub issueHow 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:
logging.addLevelName(logging.DEBUG, "debug: ")
logging.addLevelName(logging.INFO, "")
logging.addLevelName(logging.WARNING, "warning: ")
logging.addLevelName(logging.ERROR, "error: ")
logging.addLevelName(logging.CRITICAL, "critical: ")
logging.addLevelName(logging.FATAL, "fatal: ")`
This along with:
_FMT = "%(asctime)s.%(msecs)03d " + SCRIPT_NAME + ": %(levelname)s%(message)s"
LOGGING_FORMATTER = logging.Formatter(_FMT, _DATEFMT)
handler.setFormatter(LOGGING_FORMATTER)
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.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Logging - Sentry Documentation
The Sentry Python SDK will honor the configured level of each logger (set with logger.setLevel(level) ). That means that you will not see...
Read more >logging — Logging facility for Python — Python 3.11.1 ...
Logs a message with level DEBUG on this logger. The msg is the message format string, and the args are the arguments which...
Read more >sentry_sdk.integrations.logging — sentry-python 1.12.0 ...
_handler = EventHandler(level=event_level) def _handle_record(self, record): # type: (LogRecord) -> None if self._handler is not None and record.levelno ...
Read more >Django logging
How to log messages in Django, Python core logging concepts, LOGGING configuration, create log messages, log message levels, log message to files/streams ...
Read more >Python Examples of logging.Filter - ProgramCreek.com
Filter): def filter(self, record): return record.levelno in (logging. ... you can use a # mapping dictionary to convert between your application levels and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue is fixed in https://github.com/getsentry/sentry-python/pull/1449 and will be released soon.
Thanks again @rrauenza for your contribution! (See the PR on how to get you some stickers as a thank you!)
Hey @rrauenza, I have reviewed your PR: https://github.com/getsentry/sentry-python/pull/1449