--use-colors/--no-use-colors has no effect with log_config passed as file #2672
Unanswered
nectarindev
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, this option works if log_config is passed as a dict.
https://github.com/encode/uvicorn/blob/c1144fd4f130388cffc05ee17b08747ce8c1be11/uvicorn/config.py#L363
In my projects, I usually create
log_config.jsonbased on what uvicorn uses by default and add the loggers I need.https://github.com/encode/uvicorn/blob/c1144fd4f130388cffc05ee17b08747ce8c1be11/uvicorn/config.py#L68
In this scenario, it would be nice to be able to enable and disable colors via cli without hardcoding
use_colors: true/falseinlog_config.json.This option will also not affect user-created formatters that use
uvicorn.logging.DefaultFormatteranduvicorn.logging.AccessFormatter.I would suggest finding formatters that use DefaultFormatter and AccessFormatter and controlling their color if it is not explicitly specified in log_config.
{ "version": 1, "disable_existing_loggers": false, "formatters": { "default": { "()": "uvicorn.logging.DefaultFormatter", "fmt": "%(levelprefix)s %(message)s" }, "access": { "()": "uvicorn.logging.AccessFormatter", "fmt": "%(levelprefix)s %(client_addr)s - \"%(request_line)s\" %(status_code)s" } }, "handlers": { "default": { "formatter": "default", "class": "logging.StreamHandler", "stream": "ext://sys.stderr" }, "access": { "formatter": "access", "class": "logging.StreamHandler", "stream": "ext://sys.stdout" } }, "loggers": { "uvicorn": {"handlers": ["default"], "level": "INFO", "propagate": false}, "uvicorn.error": {"level": "INFO"}, "uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": false}, "my_logger": {"handlers": ["default"], "level": "INFO", "propagate": false} } }# uvicorn --factory main:create_app --no-use-colors --log-config log_config.json*console output still uses colors
If this proposal is accepted, I would like to take it on.
Beta Was this translation helpful? Give feedback.
All reactions