Created
April 14, 2012 08:29
-
-
Save vmihailenco/2382901 to your computer and use it in GitHub Desktop.
Logging mixin for Django tastypie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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