question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sentry uses logging's levelname instead of levelno when mapping to levels.

See original GitHub issue

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:

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:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
antonpirkercommented, Jun 21, 2022

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!)

1reaction
antonpirkercommented, May 25, 2022
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found