简体   繁体   English

如何将调试级别记录到文件,但仅在python屏幕上记录信息级别

[英]how to logging debug level to file but only info level on screen in python

in my python project i have several lines that are logging with debug level and other with info level. 在我的python项目中,我有几行分别以调试级别和其他信息级别进行记录。 Now, when i run my code i can set at the begging the log level to info or debug level and that will log to a file and on the screen only the info or both info/debug messages accordingly. 现在,当我运行我的代码时,我可以将日志级别设置为info或debug级别,这将记录到文件,并且在屏幕上仅记录info或相应的info / debug消息。

How can i achieve to set to log to file always debug level but on screen always info level? 我如何实现设置日志记录始终为调试级别,但屏幕上始终为信息级别?

Example (only a small part): 示例(仅一小部分):

loggername = 'Main.Case.'
self.logger = logging.getLogger(loggername)
self.logger.info('case() - Started')
self.logger.debug('System ready...')
self.logger.debug('File ready...')
self.logger.debug('Memory ready...')
self.logger.info('case() - Ready')

This would print with info level only (on screen and log file): 这将仅以信息级别打印(在屏幕和日志文件上):

Main.Case.case() - Started
Main.Case.case() - Ready

With debug level i will get (on screen and log file): 使用调试级别,我将获得(屏幕和日志文件):

Main.Case.case() - Started
Main.Case.System ready...
Main.Case.File ready...
Main.Case.Memory ready...
Main.Case.case() - Ready

I actually would like to have on screen always only the info level lines and in the log file info/debug level! 我实际上希望始终只在屏幕上显示信息级别行,并在日志文件中显示信息/调试级别!

When i activate debug level then i will get everything to both out puts (screen/file). 当我激活调试级别时,我将同时获得所有输出(屏幕/文件)。

Any one any idea?? 任何一个任何想法吗?

Thanks in adv. 感谢在广告中。

Python文档的日志记录手册记录了如何执行此操作。

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

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