Skip to content

Commit 4906d5b

Browse files
authored
ref: Refactored debug logging (#47)
1 parent 31292c9 commit 4906d5b

File tree

7 files changed

+25
-23
lines changed

7 files changed

+25
-23
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ format:
2020
tox-test:
2121
@sh ./scripts/runtox.sh
2222
.PHONY: tox-test
23+
24+
lint:
25+
@tox -e linters
26+
.PHONY: lint

sentry_sdk/hub.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55

66
from ._compat import with_metaclass
77
from .scope import Scope
8-
from .utils import exc_info_from_error, event_from_exception, get_logger, ContextVar
8+
from .utils import exc_info_from_error, event_from_exception, logger, ContextVar
99

1010

1111
_local = ContextVar("sentry_current_hub")
1212

13-
logger = get_logger(__name__)
14-
1513

1614
@contextmanager
1715
def _internal_exceptions():

sentry_sdk/integrations/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from __future__ import print_function
2-
3-
import sys
41
from threading import Lock
52

3+
from ..utils import logger
4+
65

76
_installer_lock = Lock()
87
_installed_integrations = {}
@@ -41,10 +40,10 @@ def __call__(self):
4140
assert self.identifier
4241
with _installer_lock:
4342
if self.identifier in _installed_integrations:
44-
print(
45-
"warning: %s integration for Sentry is already "
46-
"configured. Will ignore second configuration." % self.identifier,
47-
file=sys.stderr,
43+
logger.warning(
44+
"%s integration for Sentry is already "
45+
"configured. Will ignore second configuration.",
46+
self.identifier,
4847
)
4948
return
5049

sentry_sdk/integrations/logging.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
from . import Integration
1212

1313

14+
IGNORED_LOGGERS = set(["sentry_sdk.errors"])
15+
16+
17+
def ignore_logger(name):
18+
IGNORED_LOGGERS.add(name)
19+
20+
1421
class LoggingIntegration(Integration):
1522
identifier = "logging"
1623

@@ -43,7 +50,7 @@ def emit(self, record):
4350
return self._emit(record)
4451

4552
def can_record(self, record):
46-
return not record.name.startswith("sentry_sdk")
53+
return record.name not in IGNORED_LOGGERS
4754

4855
def _breadcrumb_from_record(self, record):
4956
return {

sentry_sdk/transport.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import json
44
import io
55
import urllib3
6-
import logging
76
import threading
87
import certifi
98
import sys
@@ -22,9 +21,6 @@
2221
from urllib import getproxies
2322

2423

25-
logger = logging.getLogger(__name__)
26-
27-
2824
def _make_pool(parsed_dsn, http_proxy, https_proxy):
2925
proxy = https_proxy if parsed_dsn == "https" else http_proxy
3026
if not proxy:

sentry_sdk/utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,10 @@ def strip_string(value, assume_length=None, max_length=512):
523523
return value[:max_length]
524524

525525

526-
def get_logger(name):
527-
rv = logging.getLogger(name)
528-
if not rv.handlers:
529-
rv.addHandler(logging.StreamHandler(sys.stderr))
530-
rv.setLevel(logging.DEBUG)
531-
return rv
526+
logger = logging.getLogger("sentry.errors")
527+
if not logger.handlers:
528+
logger.addHandler(logging.StreamHandler(sys.stderr))
529+
logger.setLevel(logging.DEBUG)
532530

533531

534532
try:

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ commands =
7171

7272
[testenv:linters]
7373
commands =
74-
flake8
75-
black --check .
74+
flake8 tests sentry_sdk
75+
black --check tests sentry_sdk

0 commit comments

Comments
 (0)