-
logging.basicConfig(**kwargs)
此函数,通过创建一个带有默认
Formatter
的StreamHandler
并将其添加到根日志记录器中来初始化基本配置。如果根日志记录器没有定义处理器,则debug()
,info()
,warning()
,error()
andcritical()
会自动调用basicConfig()
。如果根日志记录器已经配置了处理器,则此函数不起作用。
此函数应该在主线程中调用,且在其他线程开始之前。在Python2.7.1和3.2之前,此函数被多线程调用。有可能(极少数)处理器会被多次添加到根日志记录器,导致意外结果比如日志中信息重复。
支持以下关键字参数:
格式 描述 filename 说明创建了一个名为filename的FileHandler,而非StreamHandler filemode 如果指定了filename参数,则以此模式打开,默认是 'a'
.format 使用指定字符串格式 datefmt 使用 time.strftime()
所接受的指定日期/时间格式style If format is specified, use this style for the format string. One of '%'
,'{'
or'$'
for printf-style,str.format()
orstring.Template
respectively. Defaults to'%'
.level 指定根日志记录器级别 stream Use the specified stream to initialize the StreamHandler. Note that this argument is incompatible with filename - if both are present, a ValueError
is raised.handlers If specified, this should be an iterable of already created handlers to add to the root logger. Any handlers which don’t already have a formatter set will be assigned the default formatter created in this function. Note that this argument is incompatible with filename or stream - if both are present, a ValueError
is raised.
logging.basicConfig()详解
最新推荐文章于 2023-12-26 16:26:15 发布