admin管理员组文章数量:1391929
I have added this code to my settings.py, but it's not working (It's not logging errors warnings and ...). Django default logging works perfectly fine, debug is True in my settings and I've created logs folder manually.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'file_logging': {
'format': '{levelname} / {levelno} - {asctime} --- {pathname} in {lineno} --- {process:d} {thread:d} -- {message}',
'style': '{'
},
'email_logging': {
'format': '{levelname} at {asctime} --- {pathname} in {lineno} -- {message}',
'style': '{'
},
},
'filters': {
'debug_true_required': {
'()': 'django.utils.log.RequireDebugTrue'
}
},
'handlers': {
'full_handler': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': 'logs/full.log',
'formatter': 'file_logging',
},
'critical_handler': {
'level': 'CRITICAL',
'class': 'logging.FileHandler',
'filename': 'logs/critical.log',
'formatter': 'file_logging',
},
'error_handler': {
'level': 'ERROR',
'filters': ['debug_true_required',],
'class': 'logging.FileHandler',
'filename': 'logs/error.log',
'formatter': 'file_logging',
},
'critical_email_handler': {
'level': 'CRITICAL',
'class': 'django.utils.log.AdminEmailHandler',
'formatter': 'email_logging',
},
'error_email_handler': {
'level': 'ERROR',
'filters': ['debug_true_required',],
'class': 'django.utils.log.AdminEmailHandler',
'formatter': 'email_logging',
},
},
'loggers': {
'file_logger': {
'handlers': ['full_handler', 'critical_handler', 'error_handler'],
'level': 'INFO',
'propagate': True
},
'email_logger': {
'handlers': ['critical_email_handler', 'error_email_handler'],
'level': 'ERROR',
'propagate': True
},
}
}
I tried recreating logs folder again, but it didn't work. I then tried to change 'propagate': False to True but it didn't work again. I also tried logging manualy with this code, which works perfectly fine, and the logs saved correctly in my logging files.
logger = logging.getLogger('file_logger')
logger.info("This is a test log message.")
logger = logging.getLogger('email_logger')
logger.critical("This is a test critical message.")
本文标签: pythonI have added a custom loggin to my django project but it isn39t workingStack Overflow
版权声明:本文标题:python - I have added a custom loggin to my django project but it isn't working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744697276a2620355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论