python中,logging模块主要是处理日志的。
所谓日志,可理解为在软件运行过程中,所记录的的一些运行情况信息
软件开发人员可以根据自己的需求添加日志,日志可以帮助软件开发人员
了解软件的运行信息,对软件的维护尤为重要。 日志级别: Level When it's used
DEBUG detailed information,typically of interest only when diagnosing problems
INFO confirmation that things are working as expected
WARNING An indication that something unexpected happended,or indicative of some problem in the near future.The software is still working as expected
ERROR Due to a more serious problem,the software has not been able to perform some funciton
CRITICAL A serious error, indication that the program itself may be unable to continue running. The default level is WARNING. Here is an Example: import logging
logging.info('this is an info log!')
logging.warning('this is a warn log!') you can see the result:
WARNING:root:this is a warn log! 如果你想看到级别比较低的一些日志,你可以这样做: Here is an Example:
import logging
logging.basicConfig(filename = 'c:\\test\\hongten.log', level = logging.DEBUG)
logging.debug('this is a debug log!')
logging.info('this is an info log!')
logging.warning('this is a warn log!') you can see the result:
DEBUG:root:this is a debug log!
INFO:root:this is an info log!
WARNING:root:this is a warn log! 如果你想格式化输出日志,你可以这样做: Here is an Example:
import logging
logging.basicConfig(format = '%(levelname)s:%(message)s', level = logging.DEBUG)
logging.debug('this is a debug log!')
logging.info('this is an info log!')
logging.warning('this is a warn log!') you can see the result:
DEBUG:this is a debug log!
INFO:this is an info log!
WARNING:this is a warn log! 下面是LogRecord attributes,在格式化输出日志的时候需要用到:
Attribute name Format Description
args You shouldn’t need to format The tuple of arguments merged into msg to produce message.
this yourself.
asctime %(asctime)s 时间格式
created %(created)s 创建时间
filename %(filename)s 文件名称
levelname %(levelname)s 日志级别
levelno %(levelno)s 日志id号
lineno %(lineno)s 行号
module %(module)s 模块名称
mescs %(mescs)s Millisecond portion of the time when the LogRecord was created.
message %(message)s 日志信息
name %(name)s 日志名称
pathname %(pathname)s 文件绝对路径
process %(process)s 进程id
processName %(processName)s 进程名称
relativeCreated %(relativeCreated)s Time in milliseconds when the LogRecord was created,
relative to the time the logging module was loaded.
thread %(thread)s 线程id
threadName %(threadName)s 线程名称

最新文章

  1. jQuery的选择器中的通配符
  2. Packet for query is too large(1767212 > 1048576)mysql在存储图片时提示图片过大
  3. java web 相对路径中已/开头和不已/开头的区别
  4. Cassandra在Windows上安装及使用方法
  5. Android SlidingMenu侧滑菜单使用
  6. T-SQL 之 多表联合更新
  7. Activity singleTop启动模式
  8. #IOS-navigation中左滑pop的三种方法
  9. NPOI使用手册
  10. Win手机安卓程序初体验
  11. iscroll4实现轮播图效果
  12. 扩展kmp——原创
  13. detach() 与remove()
  14. selenium自动化测试打开新标签窗口
  15. 用django2.1开发公司官网(上)
  16. centos7换源
  17. oracle表空间不足,ORA-00604的解决方法
  18. python成长之路一
  19. 德州扑克AI--Programming Poker AI(译)
  20. rsync 同步文件如何指定属主属组和权限

热门文章

  1. SQL Server 2008登录错误:无法连接到(local)解决方法
  2. java学习笔记
  3. Gym - 101102C
  4. js计算地球两个经纬度之间的距离
  5. spark伪分布式安装
  6. Markdown 文档格式编写语法
  7. OpenGL 多视图与截屏
  8. Jetty使用教程(一)——开始使用Jetty
  9. Asp.Net MVC4 + Oracle + EasyUI 学习 序章
  10. android 无限循环的viewpager