getsentry / getsentry/sentry-python

Make `ignore_logger()` accept a log level

Abierto
#4,706 4 comentarios 0 reacciones 0 asignados Ver en GitHub
Feature Integration: Logging Logs Python
Lenguaje dominante
Python
Estrellas
2.2k
Forks
669
Merge medio
1 d 1 h
PR fusionados (30 d)
213

Descripción

### Problem Statement

We've set `LoggingIntegration(level=logging.INFO, event_level=logging.ERROR, sentry_logs_level=logging.INFO)`, and we have a somewhat noisy dependency that does a lot of logging with pretty much the whole range of levels.

We want to avoid sending the DEBUG and INFO logs of that dependency to Sentry, **but** we'd still like logs with WARNING and above to be sent, which there doesn't seem to be any simple way of doing (other than e.g. providing both `before_breadcrumb` and `before_send_log` with a callback that does that filtering manually).

### Solution Brainstorm

Change the `ignore_logger()` implementation to something like:
```python
from logging import _checkLevel

_IGNORED_LOGGERS = {
"sentry_sdk.errors": logging.CRITICAL,
"urllib3.connectionpool": logging.CRITICAL,
"urllib3.connection": logging.CRITICAL,
}

def ignore_logger(
name, *, level_or_below=logging.CRITICAL
):
_IGNORED_LOGGERS[name] = _checkLevel(level_or_below)
```
and then change `_BaseHandler._can_record()` to:
```python
class _BaseHandler(logging.Handler):
def _can_record(self, record):
for logger, level_or_below in _IGNORED_LOGGERS.items():
if (
fnmatch(record.name.strip(), logger)
and record.levelno <= level_or_below
):
return False
return True
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.