#!/usr/bin/env python
# -*- coding:utf-8 -*- 日志
import logging # 5个级别的日志 DEBUG INFO WARNING ERROR CRITICAL
"""logging.warning("1111111") #输出日志信息到屏幕
logging.critical("2222222")""" logging.basicConfig(filename='example.log',level=logging.INFO,
format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p' )
#保存日志信息到文件# level表示比这个定义级别高的信息才写入文件
logging.debug('this message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
import logging

logger =logging.getLogger('TEST-LOG')# 获取logger对象设置日志标记,不设置默认是root
logger.setLevel(logging.DEBUG)#设置全局的日志级别 ch=logging.StreamHandler()# 设置打印到屏幕的对象
ch.setLevel(logging.DEBUG)#设置打印到屏幕对象的日志级别 fh=logging.FileHandler("access.log")#设置往文件输出的对象 设置文件名称
fh.setLevel(logging.WARNING)#设置输出到文件对象的日志级别
#Formatter 参数 还有 %(filename)s-输出日志的页面文件名称 %(lineno)d-输出日志的程序行号
#%(modeule)s -页面模块名称 ,%(process)s进程名称
formatter= logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -%(message)s') ch.setFormatter(formatter)#设置输出屏幕对象的格式
fh.setFormatter(formatter)#设置输出文件对象的格式 logger.addHandler(ch)#注册屏幕输出对象
logger.addHandler(fh)#注册文件输出对象 #开始打印日志信息
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')

最新文章

  1. 重写ValidateEntity虚方法实现可控的上下文验证和自定义验证
  2. 【spring bean】 spring中bean之间的引用以及内部bean
  3. BZOJ1087状压DP 解题报告
  4. 在Eclipse中配置Tomcat时,出现Cannot create a server using the selected type错误
  5. filesort是什么意思?
  6. 【hdu3341-Lost's revenge】DP压缩+AC自动机
  7. oracle自动编号
  8. java io 流基础
  9. Array 的五种迭代方法 -----every() /filter() /forEach() /map() /some()
  10. poj 3228 Gold Transportation 二分+网络流
  11. 【前端】:jQuery下
  12. CS:APP3e 深入理解计算机系统_3e CacheLab实验
  13. 解决Warning Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
  14. 15:IO之File、Properties类
  15. 前端回顾:2016年 JavaScript 之星
  16. 配置dataimport时候 如果css样式有问题 要修改index和admin的版本号
  17. python之路——1
  18. 一步一步学android控件(之六) —— MultiAutoCompleteTextView
  19. 基于jQuery的数字键盘插件
  20. 【CodeForces】913 E. Logical Expression

热门文章

  1. apache url rewrite及正则表达式笔记
  2. [控件] LabelView
  3. UITextField使用的一些细节
  4. 也许,这样理解HTTPS更容易
  5. Python学习---模拟微信网页登录180410
  6. 铁乐学python_Day42_线程-信号量事件条件
  7. SAP 前端技术的演化史简介
  8. Latex排版全解
  9. 20165318 2017-2018-2 《Java程序设计》第八周学习总结
  10. C. Serval and Parenthesis Sequence 【括号匹配】 Codeforces Round #551 (Div. 2)