Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

event is no longer passed to Event.to_string. logging client now works

  • Loading branch information...
commit 10e8bc72baa7d9eaace21620db44c93f8aeb4b57 1 parent 6546e39
David Cramer authored gandalfar committed
1  sentry/client/__init__.py
@@ -21,7 +21,6 @@ def __get_client(self):
21 21 return client
22 22
23 23 def capture(self, *args, **kwargs):
24   - print self.__get_client().capture
25 24 return self.__get_client().capture(*args, **kwargs)
26 25
27 26 def get_client(path):
2  sentry/client/base.py
@@ -197,7 +197,7 @@ def store(self, event_type, tags, data, date, time_spent, event_id, **kwargs):
197 197 )
198 198 event.set_meta(**data)
199 199
200   - event_message = handler.to_string(event, data[handler.interface])
  200 + event_message = handler.to_string(data[handler.interface])
201 201
202 202 group, created = Group.objects.get_or_create(
203 203 type=event_type,
13 sentry/client/logging/__init__.py
@@ -21,8 +21,13 @@ def __init__(self, *args, **kwargs):
21 21 super(LoggingSentryClient, self).__init__(*args, **kwargs)
22 22 self.logger = logging.getLogger(self.logger_name)
23 23
24   - def send(self, **kwargs):
  24 + def send(self, event_type, data, **kwargs):
25 25 exc_info = sys.exc_info()
26   - self.logger.log(kwargs.pop('level', None) or self.default_level,
27   - kwargs.pop('message', None) or exc_info[0],
28   - exc_info=exc_info, extra=kwargs)
  26 +
  27 + module, class_name = event_type.rsplit('.', 1)
  28 +
  29 + handler = getattr(__import__(module, {}, {}, [class_name], -1), class_name)()
  30 +
  31 + message = handler.to_string(data[handler.interface])
  32 +
  33 + self.logger.log(self.default_level, message, exc_info=True, extra=data)
8 sentry/events.py
@@ -15,7 +15,7 @@
15 15 __all__ = ('BaseEvent', 'Exception', 'Message', 'Query')
16 16
17 17 class BaseEvent(object):
18   - def to_string(self, event, data):
  18 + def to_string(self, data):
19 19 raise NotImplementedError
20 20
21 21 def get_data(self, **kwargs):
@@ -44,7 +44,7 @@ class Exception(BaseEvent):
44 44 """
45 45 interface = 'sentry.interfaces.Exception'
46 46
47   - def to_string(self, event, data):
  47 + def to_string(self, data):
48 48 if data['value']:
49 49 return '%s: %s' % (data['type'], data['value'])
50 50 return data['type']
@@ -204,7 +204,7 @@ class Message(BaseEvent):
204 204
205 205 interface = 'sentry.interfaces.Message'
206 206
207   - def to_string(self, event, data):
  207 + def to_string(self, data):
208 208 return data['message'] % tuple(data.get('params', ()))
209 209
210 210 def get_event_hash(self, message, params=(), **kwargs):
@@ -225,7 +225,7 @@ class Query(BaseEvent):
225 225 """
226 226 interface = 'sentry.interfaces.Query'
227 227
228   - def to_string(self, event, data):
  228 + def to_string(self, data):
229 229 return data['query']
230 230
231 231 def get_event_hash(self, query, engine, **kwargs):
26 tests/test_clients/test_logging.py
... ... @@ -0,0 +1,26 @@
  1 +from .. import BaseTest
  2 +
  3 +import logging
  4 +
  5 +from sentry.client import get_client
  6 +from sentry.models import Event
  7 +
  8 +class LoggingTest(BaseTest):
  9 + def test_logging_client(self):
  10 + client = get_client('sentry.client.logging.LoggingSentryClient')
  11 +
  12 + _foo = {'': None}
  13 +
  14 + class handler(logging.Handler):
  15 + def emit(self, record):
  16 + _foo[''] = record
  17 +
  18 + logger = client.logger
  19 + logger.addHandler(handler())
  20 +
  21 + event_id = client.capture('Message', message='hello world')
  22 +
  23 + self.assertRaises(Event.DoesNotExist, Event.objects.get, event_id)
  24 +
  25 + self.assertEquals(_foo[''].getMessage(), 'hello world')
  26 + self.assertEquals(_foo[''].levelno, client.default_level)

0 comments on commit 10e8bc7

Please sign in to comment.
Something went wrong with that request. Please try again.