其中Logging一共有五种级别,依次是DEBUG < INFO < WARNING < ERROR < CRITICAL
# @Author:Runsen #引入了 logging 模块 import logging LOG_FORMAT = "%(asctime)s----%(name)s----%(levelname)s----%(message)s" #level 配置为 WARNING 信息,即只输出 WARNING 级别及其以上的信息, # format指定了 format 格式的字符串,包括asctime运行时间 name模块名称、levelname(日志级别)message (日志内容) logging.basicConfig(level=logging.WARNING,format=LOG_FORMAT) logging.debug("This is a debug log") logging.info("This is a info log") logging.warning("This is a warning log") logging.error("This is a error log") logging.critical("This is a critical log")
具体输出如下。
2020-10-31 12:15:13,181----WARNING----This is a warning log 2020-10-31 12:15:13,181----ERROR----This is a error log 2020-10-31 12:15:13,182----CRITICAL----This is a critical log