1.python提供了一个标准的日志接口,就是logging模块。日志级别有DEBUG、INFO、WARNING、ERROR、CRITICAL五种。
导入logging模块
import logging
2.默认的日志级别是ERROR
3.修改日志的级别
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=’myapp.log’,
filemode=’w’)
设置日志的输出格式和级别
format这条是定义日志格式的一个变量。显示的条目可以是以下内容:
%(levelname):日志级别的名字格式
%(levelno)s:日志级别的数字表示
%(name)s:日志名字
%(funcName)s:函数名字
%(asctime):日志时间,可以使用datefmt去定义时间格式,如上图。
%(pathname):脚本的绝对路径
%(filename):脚本的名字
%(module):模块的名字
%(thread):thread id
%(threadName):线程的名字
filemode=’w’ 这种方式会覆盖掉日志文件里面原有的内容
filemode=’a’ 不会覆盖。这种方式也是默认的方式
filename=’d:/myapp.log’ 是指日志文件的路径。可以自己指定
SightCare supports overall eye health, enhances vision, and protects against oxidative stress. Take control of your eye health and enjoy the benefits of clear and vibrant eyesight with Sight Care. https://sightcarebuynow.us/