Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 10e8bc72baa7d9eaace21620db44c93f8aeb4b57 1 parent 6546e39
@dcramer authored gandalfar committed
View
1  sentry/client/__init__.py
@@ -21,7 +21,6 @@ def __get_client(self):
return client
def capture(self, *args, **kwargs):
- print self.__get_client().capture
return self.__get_client().capture(*args, **kwargs)
def get_client(path):
View
2  sentry/client/base.py
@@ -197,7 +197,7 @@ def store(self, event_type, tags, data, date, time_spent, event_id, **kwargs):
)
event.set_meta(**data)
- event_message = handler.to_string(event, data[handler.interface])
+ event_message = handler.to_string(data[handler.interface])
group, created = Group.objects.get_or_create(
type=event_type,
View
13 sentry/client/logging/__init__.py
@@ -21,8 +21,13 @@ def __init__(self, *args, **kwargs):
super(LoggingSentryClient, self).__init__(*args, **kwargs)
self.logger = logging.getLogger(self.logger_name)
- def send(self, **kwargs):
+ def send(self, event_type, data, **kwargs):
exc_info = sys.exc_info()
- self.logger.log(kwargs.pop('level', None) or self.default_level,
- kwargs.pop('message', None) or exc_info[0],
- exc_info=exc_info, extra=kwargs)
+
+ module, class_name = event_type.rsplit('.', 1)
+
+ handler = getattr(__import__(module, {}, {}, [class_name], -1), class_name)()
+
+ message = handler.to_string(data[handler.interface])
+
+ self.logger.log(self.default_level, message, exc_info=True, extra=data)
View
8 sentry/events.py
@@ -15,7 +15,7 @@
__all__ = ('BaseEvent', 'Exception', 'Message', 'Query')
class BaseEvent(object):
- def to_string(self, event, data):
+ def to_string(self, data):
raise NotImplementedError
def get_data(self, **kwargs):
@@ -44,7 +44,7 @@ class Exception(BaseEvent):
"""
interface = 'sentry.interfaces.Exception'
- def to_string(self, event, data):
+ def to_string(self, data):
if data['value']:
return '%s: %s' % (data['type'], data['value'])
return data['type']
@@ -204,7 +204,7 @@ class Message(BaseEvent):
interface = 'sentry.interfaces.Message'
- def to_string(self, event, data):
+ def to_string(self, data):
return data['message'] % tuple(data.get('params', ()))
def get_event_hash(self, message, params=(), **kwargs):
@@ -225,7 +225,7 @@ class Query(BaseEvent):
"""
interface = 'sentry.interfaces.Query'
- def to_string(self, event, data):
+ def to_string(self, data):
return data['query']
def get_event_hash(self, query, engine, **kwargs):
View
26 tests/test_clients/test_logging.py
@@ -0,0 +1,26 @@
+from .. import BaseTest
+
+import logging
+
+from sentry.client import get_client
+from sentry.models import Event
+
+class LoggingTest(BaseTest):
+ def test_logging_client(self):
+ client = get_client('sentry.client.logging.LoggingSentryClient')
+
+ _foo = {'': None}
+
+ class handler(logging.Handler):
+ def emit(self, record):
+ _foo[''] = record
+
+ logger = client.logger
+ logger.addHandler(handler())
+
+ event_id = client.capture('Message', message='hello world')
+
+ self.assertRaises(Event.DoesNotExist, Event.objects.get, event_id)
+
+ self.assertEquals(_foo[''].getMessage(), 'hello world')
+ self.assertEquals(_foo[''].levelno, client.default_level)
Please sign in to comment.
Something went wrong with that request. Please try again.