[Django]-Django: how to set log level to INFO or DEBUG

16👍

You need to add e.g.

'core.handlers': {
    'level': 'DEBUG',
    'handlers': ['console']
}

in parallel with the django.request entry, or

'root': {
    'level': 'DEBUG',
    'handlers': ['console']
}

in parallel with the ‘loggers’ entry. This will ensure that the level is set on the logger you are actually using, rather than just the django.request logger.

Update: To show messages for all your modules, just add entries alongside django.request to include your top level modules, e.g. api, handlers, core or whatever. Since you haven’t said exactly what your package/module hierarchy is, I can’t be more specific.

6👍

I fixed it by changing

LOGGING = {
    ...
}

to:

logging.config.dictConfig({
    ...
})

For example to log all messages to the console:

import logging.config
LOGGING_CONFIG = None
logging.config.dictConfig({
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'console': {
            # exact format is not important, this is the minimum information
            'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'console',
        },
    },
    'loggers': {
    # root logger
        '': {
            'level': 'DEBUG',
            'handlers': ['console'],
        },
    },
})

Leave a comment