Created
December 12, 2012 02:00
-
-
Save selwin/4264218 to your computer and use it in GitHub Desktop.
Django's management command base that logs errors
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
from __future__ import with_statement | |
import sys | |
import django | |
from django.core.management.base import BaseCommand | |
from django.utils.log import getLogger | |
class LoggingBaseCommand(BaseCommand): | |
# A subclass of BaseCommand that logs errors to django.commands | |
def __init__(self): | |
super(LoggingBaseCommand, self).__init__() | |
self._logger = getLogger('django.commands') | |
def run_from_argv(self, argv): | |
try: | |
super(LoggingBaseCommand, self).run_from_argv(argv) | |
except Exception, e: | |
self._logger.error(e, | |
exc_info=sys.exc_info(), | |
extra={ | |
'status_code': 500, | |
} | |
) | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment