Django日志格式未应用

der*_*ble 3 python django logging

我按照django网站(https://docs.djangoproject.com/en/1.7/topics/logging/#examples)的指示在我的django应用程序中添加了一些记录器,但无论出于何种原因,日志都没有应用这些格式.这是我的记录器设置:

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
    'verbose': {
        'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
    },
    'simple': {
        'format': '%(asctime)s : module %(name)s : %(message)s'
    },
},
'filters': {
    'require_debug_false': {
        '()': 'django.utils.log.RequireDebugFalse'
    },
'require_debug_true': {
    '()': 'django.utils.log.RequireDebugTrue',
    }
 },
'handlers': {
    'null': {
        'level': 'DEBUG',
        'class': 'logging.NullHandler',
    },
    'mail_admins': {
        'level': 'ERROR',
        'filters': ['require_debug_false'],
        'class': 'django.utils.log.AdminEmailHandler'
        },
    'file_request': {
        'level': 'WARNING',
        'class': 'logging.handlers.RotatingFileHandler',   
        'filename': os.path.join(file_root, 'request' , 'wilkins_request.log'),
        'maxBytes': 1024*1024*1, # 1MB
        'backupCount': 0,
        },    
    'file_backend': {
        'level': 'DEBUG',
        'class': 'logging.handlers.RotatingFileHandler',
        'filters': ['require_debug_true'],    
        'filename': os.path.join(file_root, 'backend' , 'wilkins_backend.log'),
        'maxBytes': 1024*1024*6, # 6MB
        'backupCount': 0,
        },    
    'file_security': {
        'level': 'DEBUG',
        'class': 'logging.handlers.RotatingFileHandler',   
        'filename': os.path.join(file_root, 'backend' , 'wilkins_security.log'),
        'maxBytes': 1024*1024*6, # 6MB
        'backupCount': 0,
        },    
    'file_migrations': {
        'level': 'DEBUG',
        'class': 'logging.handlers.RotatingFileHandler',   
        'filename': os.path.join(file_root, 'backend' , 'wilkins_migrations.log'),
        'maxBytes': 1024*1024*1, # 1MB
        'backupCount': 0,
        },    
    'file_debug': {
        'level': 'DEBUG',
        'class': 'logging.handlers.RotatingFileHandler', 
        'filters': ['require_debug_true'],  
        'filename': os.path.join(file_root, 'debug' , 'wilkins.log'),
        'filters': ['require_debug_true'],
        'maxBytes': 1024*1024*1, # 1MB
        'backupCount': 0,
        },    
 },
'loggers': {
    'django': {
        'handlers': ['null'],
        'propagate': True,
        'level': 'INFO',
        'formatter': 'simple'
        },
    'django.request': {
        'handlers': ['file_request'],
        'level': 'WARNING',
        'propagate': True,
        'formatter': 'simple'
        },
    'django.security': {
        'handlers': ['file_security'],
        'level': 'INFO',
        'propagate': True,
        'formatter': 'simple'
        },
    'django.db.backends': {
        'handlers': ['file_backend'],
        'level': 'DEBUG',
        'propagate': False,
        'formatter': 'simple'
        },
    'django.db.backends.schema': {
        'handlers': ['file_migrations'],
        'level': 'DEBUG',
        'propagate': False,
        'formatter': 'simple'
        },
    'wilkins': {
        'handlers': ['file_debug'],
        'level': 'DEBUG',
        'propagate': True,
        'formatter': 'simple'
        },
}
Run Code Online (Sandbox Code Playgroud)

}

但我的输出看起来像这样:

(来自wilkins_request.log)

Not Found: /accounts/login9
Not Found: /accounts/login9
Not Found: /accounts/login9
Not Found: /l
Not Found: /l
Not Found: /l
Not Found: /favicon.ico
Run Code Online (Sandbox Code Playgroud)

(来自wilkins.log)

Made it to the Projects view.
Made it to the Projects view.
Made it to the Projects view.
Made it to the Projects view.
Run Code Online (Sandbox Code Playgroud)

我完全不知道为什么会这样.我正在使用股票Django 1.7,所以我没有更改django中的任何代码路径或设置,除了这个日志变量.

Vin*_*jip 7

格式化程序适用于处理程序,而不适用于记录程序.将这些formatter:行移动到处理程序dicts,事情应该按预期工作.

  • 谢谢。我不敢相信我的配置没有正确。我知道它又蠢又小。 (2认同)