现在的项目用Flask实现了一个事件处理服务,会从MQ中接收消息进行格转后写入到MySQL数据库。
所有的日志都是通过logging模块同时打到文件和标准输出。
在用tornado运行flask的时候发现标准输出的日志内容格式异常:
vs INFO 2015-12-01 17:30:36,518 [ sqs_utils(16):93:read_messages ] SQS: event name ObjectRemoved:Delete will be ignored
INFO:vvs:SQS: event name ObjectRemoved:Delete will be ignored
例如上面的日志,第一行为日志模块实际输出的效果。莫名其妙的会出现第二行这种格式的日志。
由于应用部署在docker中,日志最好直接打到标准输出,所以请问有什么好的解决办法没?
The second log record should be the handler output of the root logger. By default, the log will be processed between handlers and bubble up to the upper layer.
The following is the code for logging
callHandlers
.callHandlers
的代码。找到输出第一条日志的
Find thelogger
对象,设置logger.propagate = 0
rrreeelogger
object that outputs the first log, and setlogger.propagate = 0
to avoid outputting the second log. 🎜