Skip to content

Instantly share code, notes, and snippets.

@ninapavlich
Last active May 29, 2019 23:52
Show Gist options
  • Save ninapavlich/a011e1acc8dbd43811a4275cfcf3dfda to your computer and use it in GitHub Desktop.
Save ninapavlich/a011e1acc8dbd43811a4275cfcf3dfda to your computer and use it in GitHub Desktop.
Example Django command for testing different logging levels
import logging
from django.core.management.base import BaseCommand, CommandError
logger = logging.getLogger('django')
class Command(BaseCommand):
def handle(self, *args, **options):
log = logging.getLogger('django')
log.debug("Testing debug message")
log.info("Testing info message")
log.warn("Testing warning message")
log.error("Testing error message")
log.critical("Testing error message")
try:
raise ValueError('This is an error that has not been caught')
except Exception as e:
logger.error(u"Catching example error: %s"%(e))
raise ValueError('This is an error that has been caught')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment