Created
January 1, 2020 04:20
-
-
Save kryogenic/54620dc4cd770d0ae9c3040c071dc4fb to your computer and use it in GitHub Desktop.
Example of using Django's built in verbosity argument to set log level in a management command
This file contains hidden or 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 import BaseCommand | |
log = logging.getLogger(__name__) | |
class Command(BaseCommand): | |
def handle(self, *args, **options): | |
log.setLevel(logging.DEBUG if int(options['verbosity']) > 1 else logging.INFO) | |
log.info('Normal output') | |
log.debug('Verbose output') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment