我想用python的日志模块捆绑相等的连续消息。 这样我想要防止包含数千条相同消息的巨大日志文件。相反,只应为日志写入日志,例如第1,第2,第3,第10,第50,第100,第500,...将不同的消息发送到记录器的时间。
如何使用logging模块实现这一目标?
这是一个例子:
而不是:
2017-07-16 16:00:00 INFO: File upload initiated
2017-07-16 16:01:00 ERROR: I/O Error: no route to host
2017-07-16 16:02:00 ERROR: I/O Error: no route to host
2017-07-16 16:03:00 ERROR: I/O Error: no route to host
2017-07-16 16:04:00 ERROR: I/O Error: no route to host
2017-07-16 16:05:00 ERROR: I/O Error: no route to host
... [169 more lines]
2017-07-16 18:54:00 ERROR: I/O Error: no route to host
2017-07-16 18:55:00 ERROR: I/O Error: no route to host
2017-07-16 18:56:00 INFO: File upload started
我希望他们以任何方式捆绑,例如:
2017-07-16 16:00:00 INFO: File upload initiated
2017-07-16 16:01:00 ERROR: I/O Error: no route to host
2017-07-16 16:02:00 ERROR: I/O Error: no route to host
2017-07-16 16:03:00 ERROR: I/O Error: no route to host
2017-07-16 16:13:00 ERROR (repeated 10x): I/O Error: no route to host
2017-07-16 17:03:00 ERROR (repeated 50x): I/O Error: no route to host
2017-07-16 18:43:00 ERROR (repeated 100x): I/O Error: no route to host
2017-07-16 18:55:00 ERROR (repeated 12x): I/O Error: no route to host
2017-07-16 18:56:00 INFO: File upload started