Python/django根记录器级别

Rom*_*giy 9 python django logging

在我的django项目中,我有以下LOGGING配置:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(name)s %(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class':'django.utils.log.NullHandler',
        },
        'sentry': {
            'level': 'DEBUG',
            'class': 'sentry.client.handlers.SentryHandler',
            'formatter': 'verbose'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django.db.backends': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': False,
        },
        '': {
            'level': 'ERROR',
            'handlers': ['console'],
        },
    },
}
Run Code Online (Sandbox Code Playgroud)

在运行时manage.py migrate我仍然在控制台中有很多调试内容,例如:

DEBUG south 2011-08-08 11:22:23,847 generic 19539 140735078710464 south execute "..."
Run Code Online (Sandbox Code Playgroud)

因为我将根记录器级别设置为ERROR,所以我期待控制台中只有错误消息.我究竟做错了什么?

UPDATE

看起来问题出在south.logger模块中:

import sys
import logging
from django.conf import settings

# Create a dummy handler to use for now.
class NullHandler(logging.Handler):
    def emit(self, record):
        pass

_logger = logging.getLogger("south")
_logger.addHandler(NullHandler())
_logger.setLevel(logging.DEBUG)
Run Code Online (Sandbox Code Playgroud)

删除_logger.setLevel(logging.DEBUG)日志记录后按预期工作.

有人能解释我这种奇怪的行为吗?

Vin*_*jip 12

南方开发者不应该真正将其顶级记录器级别设置为DEBUG.事实上,如果他们根本没有设置它,它将继承根记录器的级别,通常由应用程序开发人员定义(在这种情况下我猜你就是这样).

我建议你将此报告为相关南方论坛的错误.