我是日志模块的新手。我想知道如何不断更新日志文件,不包括响应消息,如2018-06-07 11:33:22,330|INFO|"POST /MyProject/ HTTP/1.1" 200 36
.
settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s|%(levelname)s|%(message)s'
}
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': "logging.handlers.RotatingFileHandler",
'formatter': 'standard',
'filename': "C:\\ProgramData\\PROGRAMX\\Logs\\PROGRAMX_logs_%s.txt" % (datetime.today().strftime("%Y_%m_%d"))
}
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
'format': '%(asctime)s|%(levelname)s|%(message)s'
}
}
}
我正在更新登录 django 之类的,
import logging
log = logging.getLogger('django')
log.error("Internal Error: X happened.")
我想完成两个任务:
1. 请求处理后立即更新日志文件。
2. 在日志文件中,我不想添加类似"POST /MyProject/ HTTP/1.1" 200 36
.
PROGRAMX_logs_2018_06_07.txt
2018-06-07 11:33:14,317|ERROR|Internal Error: X happened.
2018-06-07 11:33:14,319|INFO|"POST /MyProject/ HTTP/1.1" 200 36
2018-06-07 11:33:22,327|ERROR|Internal Error: X happened.
2018-06-07 11:33:22,330|INFO|"POST /MyProject/ HTTP/1.1" 200 36