python - tornado + flask 如何处理日志?
伊谢尔伦
伊谢尔伦 2017-04-17 16:48:41
0
1
383

现在的项目用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中,日志最好直接打到标准输出,所以请问有什么好的解决办法没?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
刘奇

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的代码。

c = self
found = 0
while c:
    for hdlr in c.handlers:
        found = found + 1
        if record.levelno >= hdlr.level:
            hdlr.handle(record)
    if not c.propagate:
        c = None    #break out
    else:
        c = c.parent
        

找到输出第一条日志的logger对象,设置 logger.propagate = 0 rrreee

Find the logger object that outputs the first log, and set logger.propagate = 0 to avoid outputting the second log. 🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!