Last active
May 29, 2019 23:52
-
-
Save ninapavlich/a011e1acc8dbd43811a4275cfcf3dfda to your computer and use it in GitHub Desktop.
Example Django command for testing different logging levels
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
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