Django 日志记录不显示参数
我在自定义 django-admin 命令中有这一行:
logger.info("%d records updated", records_updated)
当我运行该命令时,日志文件和控制台输出显示我所期望的内容:
[2011-09-02 03:49:31,405] INFO::(27041 140698227433576)::update_records - 5 records updated
但是,发送给管理员的电子邮件显示
INFO: %d records updated #This is the subject and body of the email the admin receives
这是我在 settings.py 文件中的日志记录信息:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'default': {
'format': '[%(asctime)s] %(levelname)s::(%(process)d %(thread)d)::%(module)s - %(message)s'
},
},
'handlers': {
'email_admins': {
'level': 'INFO',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
'formatter': 'default',
},
'admin_console': {
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'default'
},
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
'formatter': 'default',
},
'file_handler': {
'level': 'DEBUG',
'formatter':'default',
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename':'logs/Project_log',
'when':'midnight',
'interval':1,
},
'request_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': 'logs/django_request.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'default',
},
},
'loggers': {
'': {
'handlers': ['email_admins', 'file_handler', 'admin_console'],
'level': 'DEBUG',
'propagate': True,
},
'django': {
'handlers':['null'],
'propagate': True,
'level':'INFO',
},
'django.request': {
'handlers': ['email_admins', 'request_handler'],
'level': 'ERROR',
'propagate': False,
},
}
任何
反馈表示赞赏。
I have this line in a custom django-admin command:
logger.info("%d records updated", records_updated)
When I run the command, the log file and console output show what I would expect:
[2011-09-02 03:49:31,405] INFO::(27041 140698227433576)::update_records - 5 records updated
However, the email to the admin shows
INFO: %d records updated #This is the subject and body of the email the admin receives
This is my logging info in the settings.py file:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'default': {
'format': '[%(asctime)s] %(levelname)s::(%(process)d %(thread)d)::%(module)s - %(message)s'
},
},
'handlers': {
'email_admins': {
'level': 'INFO',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
'formatter': 'default',
},
'admin_console': {
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'default'
},
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
'formatter': 'default',
},
'file_handler': {
'level': 'DEBUG',
'formatter':'default',
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename':'logs/Project_log',
'when':'midnight',
'interval':1,
},
'request_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': 'logs/django_request.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'default',
},
},
'loggers': {
'': {
'handlers': ['email_admins', 'file_handler', 'admin_console'],
'level': 'DEBUG',
'propagate': True,
},
'django': {
'handlers':['null'],
'propagate': True,
'level':'INFO',
},
'django.request': {
'handlers': ['email_admins', 'request_handler'],
'level': 'ERROR',
'propagate': False,
},
}
}
Any feedback appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
logger.info("%d条记录已更新" %records_updated)
也许你应该这样写?
logger.info("%d records updated" % records_updated)
Maybe u should write like this?