### logging

- logging.debug

- logging.info

- logging.warning

- logging.error

- logging.critical

--------------------------------

import   logging
logging.basicConfig(level=logging.DEBUG)
logging.debug("this is a debug")
logging.info("this is info")
logging.warning("this is warning")
logging.error("this is error")
logging.critical("this is critical")
--------------------------------
### 装饰器
- 使用装饰器,打印函数执行的时间
----------------------------------
import logging
LOG_FORMART = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(format = LOG_FORMART)
def log(func):
    def wrapper(*arg, **kw):
        logging.error("this is info message")
        return func(*arg, **kw)
    return wrapper
@log
def test():
    print("test done")
   
test()
------------------------------------------
#####   使用装饰器,根据不同的函数,传入的日志不相同
LOG_FORMART = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(format = LOG_FORMART, filename = "my.log")
def log(text):
    def decorator(func):
        def wrapper(*arg, **kw):
            logging.error(text)
            return func(*arg, **kw)
        return wrapper
    return decorator
@log("test done")
def test():
    print("test done")
   
@log("main log")
def main():
    print("main done")
test()
main()
-----------------------------------------
 

最新文章

  1. SQLite
  2. 瞄准SMART目标
  3. C#中将DataTable转成List
  4. 打开mysql时,提示 1040,Too many connections
  5. Asp.net MVC中提交集合对象,实现Model绑定
  6. HDOJ 2181 哈密顿绕行世界问题
  7. android文字阴影效果设置
  8. 【HDOJ】3496 Watch The Movie
  9. maven错误解决:编码GBK的不可映射字符
  10. The Time in Words
  11. [转] Lisp语言:Do循环的使用
  12. python web with bottle and session (beaker)
  13. 第七章——DMVs和DMFs(4)——用DMV和DMF监控磁盘IO
  14. JSP内置对象--response对象 (addCookie(),setHeader(),sendRedirect())
  15. nginx slab内存管理
  16. Hybrid容器设计之第三方网站
  17. 【php增删改查实例】第二十六节 - 个人详情页制作
  18. linux中执行shell命令的几种常用方法
  19. 由通过seeion识别保存在cookie中的seeionID引发的CSRF问题
  20. Android开发 ---基本UI组件4:拖动事件、评分进度条、圆圈式进度条、进度条控制

热门文章

  1. 【flask】项目集成Sentry收集线上错误日志
  2. java数字加密算法
  3. linux使用ltrace和strace跟踪程序执行过程
  4. C#银行卡号每隔4位数字加一个空格
  5. word定义多级列表
  6. Spark-Core RDD中函数(变量)传递
  7. 你知道 Java 类是如何被加载的吗?
  8. java常用类详细介绍及总结:字符串相关类、日期时间API、比较器接口、System、Math、BigInteger与BigDecimal
  9. 【暑假培训1】test1
  10. JZOJ2678 树B