网页
综合
更新时间 2026-11-14 16:46:33
Logging - Uvicorn
自动蜘蛛
uvicorn.dev
正文约 1636 字
Uvicorn uses Python's built-in logging module, and provides three loggers out of the box:
Despite its name, uvicorn.error is not limited to error messages. It is the general-purpose server logger, similar to how Gunicorn names its main logger. See #562 for background.
By default, Uvicorn applies the following dictConfig() configuration:
You can supply a custom logging configuration file with the --log-config option (or log_config when calling uvicorn.run()).
Uvicorn supports three file formats:
Create a file named log_config.yaml:
Then pass it to Uvicorn:
Create a file named log_config.json:
You can also pass a dictionary directly when running programmatically:
To write Uvicorn's server logs to a file in addition to the console, add a FileHandler to the uvicorn logger:
In this example, uvicorn.access still writes to stdout only. To write access logs to the file as well, add file to the uvicorn.access.handlers list.
Use the --no-access-log CLI flag, or set access_log=False programmatically. This removes all handlers from uvicorn.access without affecting the uvicorn.error logger.
Pass --no-use-colors on the command line, or set use_colors=False programmatically. When using a custom --log-config, set use_colors: false on each formatter that extends uvicorn.logging.ColourizedFormatter.
If you do not need Uvicorn's colorized output, you can use the standard logging.Formatter instead:
When using a standard logging.Formatter for the access logger, the %(client_addr)s, %(request_line)s, and %(status_code)s placeholders are not available. The access log line will be formatted using only the standard %(message)s field.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。