logging模块简单用法

Posted dingbj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了logging模块简单用法相关的知识,希望对你有一定的参考价值。

 

logging模块功能比较多,但一般情况下使用其简单功能就已经足够了。

 

最简单的用法如下:

import logging

logging.baiscConfig(level=logging.DEBUG)

logging.debug(‘message‘)

logging.critical(‘message‘)

logging.warning(%s before you %s, ‘Look‘, ‘leap!‘)

logging.warning(‘{} before you {}.format(‘Look‘‘leap!‘))

 

如果对日志格式、输出、日期格式等有要求,可以增加basicConfig的关键字参数,如:

logging.basicConfig(filename=‘example.log‘,level=logging.DEBUG)


对于basicConfig方法所有的关键字参数如下:

 logging.basicConfig(**kwargs)

Does basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger. The functions debug()info()warning()error() and critical() will call basicConfig() automatically if no handlers are defined for the root logger.

技术图片

 

技术图片

 

以上是关于logging模块简单用法的主要内容,如果未能解决你的问题,请参考以下文章