python学习笔记 --- logging日志模块

来源:互联网 发布:ubuntu安装twisted 编辑:程序博客网 时间:2024/05/21 04:41

简单用例将日志信息打印出来:

打印共分为几类:

[debug]

[info]

[warning]

[error]

[critical]


import logginglogging.debug('debug message')logging.info('info message')logging.warning('warning message')logging.error('error message')logging.critical('critical message')

综合示例:

import logginglogging.basicConfig(level=logging.DEBUG,                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',                    datefmt='%a, %d %b %Y %H:%M:%S',                    filename='/tmp/test.log',                    filemode='w')logging.debug('debug message')logging.info('info message')logging.warning('warning message')logging.error('error message')logging.critical('critical message')

可通过查看文件内容查看日志信息。


0 0