Django: how to set log level to INFO or DEBUG

浪尽此生 提交于 2019-12-03 03:23: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.

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'],
        },
    },
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!