有什么方法可以在Python中为日志记录模块配置缓冲区 [英] Is there any way to configure buffer for logging module in Python

查看:55
本文介绍了有什么方法可以在Python中为日志记录模块配置缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有冗长的日志记录,它似乎在极大地影响我的Python程序的性能.据我了解,似乎默认情况下,Python日志记录模块将缓冲直到一条日志消息.是否可以为几个日志消息配置此缓冲区?例如,我可以使Python日志记录模块最多缓冲10条消息吗?我已经阅读了Python文档,还堆积了诸如 this之类的溢出问题,但没有明确的答案,因此将其发布.

I have verbose logging and it looks like it is significantly impacting the performance of my Python program. From what I've understood, it seems that by default, the Python logging module will buffer until one log message. Is it possible to configure this buffer for several log messages? For example, can I make the Python logging module buffer up to 10 messages? I have gone through the Python documentation and also stack overflow questions like this, this and this but there is no clear answer and therefore posting this.

谢谢您的输入.

推荐答案

使用

Use the MemoryHandler. It does exactly what you want. It buffers messages until some criteria are met and then sends them to another handler to be handled.

这篇关于有什么方法可以在Python中为日志记录模块配置缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆