Skip to content

Commit

Permalink
Dont fail hard when logging handlers raise an exception (fixes getsen…
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Aug 6, 2012
1 parent 3745322 commit 21386e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
16 changes: 6 additions & 10 deletions raven/handlers/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ def __init__(self, *args, **kwargs):
super(SentryHandler, self).__init__(*args, **kwargs)

def emit(self, record):
# from sentry.client.middleware import SentryLogMiddleware

# # Fetch the request from a threadlocal variable, if available
# request = getattr(SentryLogMiddleware.thread, 'request', None)
self.format(record)
try:
self.format(record)

# Avoid typical config issues by overriding loggers behavior
if record.channel.startswith('sentry.errors'):
print >> sys.stderr, to_string(record.message)
return
# Avoid typical config issues by overriding loggers behavior
if record.channel.startswith('sentry.errors'):
print >> sys.stderr, to_string(record.message)
return

try:
return self._emit(record)
except Exception:
print >> sys.stderr, "Top level Sentry exception caught - failed creating log record"
Expand Down
17 changes: 6 additions & 11 deletions raven/handlers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,14 @@ def __init__(self, *args, **kwargs):
logging.Handler.__init__(self, level=kwargs.get('level', logging.NOTSET))

def emit(self, record):
# from sentry.client.middleware import SentryLogMiddleware

# # Fetch the request from a threadlocal variable, if available
# request = getattr(SentryLogMiddleware.thread, 'request', None)

self.format(record)
try:
self.format(record)

# Avoid typical config issues by overriding loggers behavior
if record.name.startswith('sentry.errors'):
print >> sys.stderr, to_string(record.message)
return
# Avoid typical config issues by overriding loggers behavior
if record.name.startswith('sentry.errors'):
print >> sys.stderr, to_string(record.message)
return

try:
return self._emit(record)
except Exception:
print >> sys.stderr, "Top level Sentry exception caught - failed creating log record"
Expand Down

0 comments on commit 21386e4

Please sign in to comment.