我在uvicorn's源代码中看到了python dict日志配置
在这方面,他们将格式化程序定义为
{
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(levelprefix)s %(asctime)s %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
"access": {
"()": "uvicorn.logging.AccessFormatter",
"fmt": '%(levelprefix)s %(asctime)s :: %(client_addr)s - "%(request_line)s" %(status_code)s',
"use_colors": True
},
}
另外,我们可以看到,他们将一个空的记录器(不确定该怎么称呼它)定义为
"": {"handlers": ["default"], "level": "INFO"},
^^^^ - see, Empty key
这是我的问题
"()"
做什么李>""
做什么李>
此字典用于配置使用^{} 的日志记录
"()"
键表示需要自定义实例化[source]:对于OP问题中的格式化程序配置,
"()"
表示应该使用这些类来实例化Formatter
我在字典的loggers部分没有看到空字符串,但下面是related docs:
因此
loggers
字典中的""
键将实例化名为""
的记录器,如logging.getLogger("")
出于各种原因,可以使用自定义日志格式化程序
uvicorn
使用自定义格式化程序to log different levels in different colors。Python日志记录手册在记录消息时使用了example of using a custom formatter to use UTC times而不是本地时间这是输出。注意,在第一行中,使用UTC时间而不是本地时间,因为使用了
UTCFormatter
相关问题 更多 >
编程相关推荐