Skip to content

Commit

Permalink
Use logging levelno instead of levelname. Levelnames can be overridden
Browse files Browse the repository at this point in the history
See #1443
  • Loading branch information
rrauenza committed May 20, 2022
1 parent 23e0295 commit cc9af0e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions sentry_sdk/integrations/logging.py
Expand Up @@ -110,17 +110,25 @@ def _breadcrumb_from_record(record):
# type: (LogRecord) -> Dict[str, Any]
return {
"type": "log",
"level": _logging_to_event_level(record.levelname),
"level": _logging_to_event_level(record),
"category": record.name,
"message": record.message,
"timestamp": datetime.datetime.utcfromtimestamp(record.created),
"data": _extra_from_record(record),
}


def _logging_to_event_level(levelname):
# type: (str) -> str
return {"critical": "fatal"}.get(levelname.lower(), levelname.lower())
def _logging_to_event_level(record):
# type: (LogRecord) -> str
default = 'error'
return {
logging.DEBUG: 'debug',
logging.INFO: 'info',
logging.WARNING: 'warning',
logging.ERROR: 'error',
logging.CRITICAL: 'critical',
logging.FATAL: 'fatal', # CRITICAL is same as FATAL
}.get(record.levelno, default)


COMMON_RECORD_ATTRS = frozenset(
Expand Down Expand Up @@ -220,7 +228,7 @@ def _emit(self, record):

hint["log_record"] = record

event["level"] = _logging_to_event_level(record.levelname)
event["level"] = _logging_to_event_level(record)
event["logger"] = record.name

# Log records from `warnings` module as separate issues
Expand Down

0 comments on commit cc9af0e

Please sign in to comment.