简体   繁体   English

有什么方法可以为 Python 中的日志记录模块配置缓冲区

[英]Is there any way to configure buffer for logging module in Python

I have verbose logging and it looks like it is significantly impacting the performance of my Python program.我有详细的日志记录,看起来它显着影响了我的 Python 程序的性能。 From what I've understood, it seems that by default, the Python logging module will buffer until one log message.据我了解,似乎默认情况下,Python 日志记录模块将缓冲直到一条日志消息。 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?例如,我可以让 Python 日志记录模块缓冲多达 10 条消息吗? 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.我已经浏览了 Python 文档以及类似这样的堆栈溢出问题, thisthis但是没有明确的答案,因此发布了这个。

Thank you for any input.感谢您的任何意见。

Use the MemoryHandler .使用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.它缓冲消息直到满足某些条件,然后将它们发送到另一个处理程序进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM