Skip to content

Instantly share code, notes, and snippets.

@vmihailenco
Created April 14, 2012 08:29
Show Gist options
  • Save vmihailenco/2382901 to your computer and use it in GitHub Desktop.
Save vmihailenco/2382901 to your computer and use it in GitHub Desktop.
Logging mixin for Django tastypie
class LoggingMixin(object):
def dispatch(self, request_type, request, **kwargs):
logger.debug(
'%s %s %s' %
(request.method, request.get_full_path(), request.raw_post_data))
try:
response = super(LoggingMixin, self).dispatch(
request_type, request, **kwargs)
except (BadRequest, fields.ApiFieldError), e:
logger.debug(
'Response 400 %s' % e.args[0])
raise
except ValidationError, e:
logger.debug(
'Response 400 %s' % e.messages)
raise
except Exception, e:
if hasattr(e, 'response'):
logger.debug(
'Response %s %s' %
(e.response.status_code, e.response.content))
else:
logger.debug('Response 500')
raise
logger.debug(
'Response %s %s' % (response.status_code, response.content))
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment