码迷,mamicode.com
首页 > 编程语言 > 详细

python日志logging

时间:2019-12-22 10:26:44      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:ace   info   com   icc   http   name   config   filename   file   

一、logging基本https://www.cnblogs.com/huaizhi/p/11245246.html


import logging

logging.basicConfig() ---默认项
logging.debug(‘This is a debug message‘)
logging.info(‘This is an info message‘)
logging.warning(‘This is a warning message‘)
logging.error(‘This is an error message‘)
logging.critical(‘This is a critical message‘)
=========== 默认配置项,只会打印warning级别以及以上级别

WARNING:root:This is a warning message
ERROR:root:This is an error message
CRITICAL:root:This is a critical message

 

添加参数后:

import logging

logging.basicConfig(filename=log.text, filemode=w, format="%(asctime)s  %(name)s  %(levelname)s:%(message)s",
                    datefmt=%d-%M-%Y %H:%M:%S, level=logging.INFO)     --指定了文件后,就不会再控制台打印,会直接存到指定文件中

logging.debug(This is a debug message)
logging.info(This is an info message)
logging.warning(This is a warning message)
logging.error(This is an error message)
logging.critical(This is a critical message)


try:
    print(5 / 0)
except Exception as e:
    logging.exception(occurred)      --可以打印出具体的问题。

 

 

 

1.实现一个py文件一个日志,且日志大于5M自动覆盖https://www.cnblogs.com/yfacesclub/p/9001073.html

2.

python日志logging

标签:ace   info   com   icc   http   name   config   filename   file   

原文地址:https://www.cnblogs.com/tarzen213/p/12079043.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!