[英]Python: How to log debug+ messages only when an error occures, info+ otherwise
My objective: 我的目标:
I found logging.handlers.MemoryHandler class: https://docs.python.org/2/library/logging.handlers.html#memoryhandler 我找到了logging.handlers.MemoryHandler类: https : //docs.python.org/2/library/logging.handlers.html#memoryhandler
It partly fits my purpose. 这部分符合我的目的。 It buffers all messages and flushes them whenever an error-level message appears.
它会缓冲所有消息并在出现错误级别的消息时刷新它们。 But if there is no error-message, it won't log anything at all.
但是,如果没有错误消息,它将根本不会记录任何内容。
I want my app to still log INFOs and WARNINGs if there were no error. 如果没有错误,我希望我的应用仍记录信息和警告。
What's the best way to implement that? 最好的实现方法是什么?
The way I see it you can achieve something similar by configuring two loggers. 我的看法是,可以通过配置两个记录器来实现类似的目的。
As an example see the documentation 作为示例,请参见文档
You can decide how to log them, same file (maybe) or separate files (my-simple.log and my-detailed.log) 您可以决定如何记录它们,相同文件(也许)或单独文件(my-simple.log和my-detailed.log)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.