log日志模块

import logging

# 在logging.basciConfig中指定文件中写入
logging.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="E:\test_allchips\log\logs\test.log", # 注意xpath指定目录文件
filemode='a')
logging.debug("User %s is loging" % 'jeck')
logging.info("User %s attempted wrong password" % 'fuzj')
logging.warning("user %s attempted wrong password more than 3 times" % 'mary')
logging.error("select db is timeout")
logging.critical("server is down")

# 打印到屏幕
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S')
logging.debug("User %s is loging" % 'jeck')
logging.info("User %s attempted wrong password" % 'fuzj')
logging.warning("user %s attempted wrong password more than 3 times" % 'mary')
logging.error("select db is timeout")
logging.critical("server is down")

logging的四大组件
  • Loggers 提供应用程序可直接使用的接口
  • Handlers 发送日志到适当的目的地
  • Filters 提供了过滤日志信息的方法
  • Formatters 指定日志显示格式
原文地址:https://www.cnblogs.com/yancy03/p/10177868.html