简体   繁体   中英

How to see debug logs from django-admin.py commands

I have a cron job that executes django-admin.py command. Sometimes that command raises an exception, and I receive an email about it.

The email only contains the traceback of the exception. But I want to also see everything that was produced via log.debug(...) in that run. Is that possible?

Here's my LOGGING that I use on my dev (where I was trying to reproduce it) -- so in this case I'd like to see the debug logs in the console since I don't email myself in dev.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format' : ("[%(asctime)s] - %(levelname)s %(module)s.%(funcName)s:"
                        "%(lineno)s (%(name)s) %(message)s"),
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
        'colored': {
            'format' : ("[%(asctime)s] -\033[1;35m %(levelname)s\033[0m "
                        "%(name)s %(funcName)s:"
                        "%(lineno)s \033[1m%(message)s\033[0m"),
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
    },
    'handlers': {
        'logfile': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': "logfile",
            'maxBytes': 50000,
            'backupCount': 2,
            'formatter': 'standard',
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'colored'
        },
    },
    'loggers': {
        '': {
            'handlers': ['console', 'logfile'],
            'level': 'DEBUG',
            'propagate': True
        },
    }
}

Had to change my console logging level to allow 'DEBUG'. Ended up removing level overwrite on the 'handlers' and just specify them per-logger. Added specific loggers for management commands rather than just use a catch-all logger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM