Skip to content

add support for custom --log-config#332

Closed
regisin wants to merge 2 commits intofastapi:mainfrom
regisin:add-log_config-option
Closed

add support for custom --log-config#332
regisin wants to merge 2 commits intofastapi:mainfrom
regisin:add-log_config-option

Conversation

@regisin
Copy link

@regisin regisin commented Mar 6, 2026

Uvicorn let's you specify a custom format for logging: https://uvicorn.dev/settings/#logging

This PR allows the user to do so via fastapi-cli: fastapi dev --log-config /path/to/log_config.yaml.

Example config file (includes client IP in the logs):

version: 1
disable_existing_loggers: false

formatters:
  default:
    "()": uvicorn.logging.DefaultFormatter
    fmt: "%(levelprefix)s %(asctime)s | %(message)s"
    use_colors: true
  access:
    "()": uvicorn.logging.AccessFormatter
    "fmt": '%(levelprefix)s %(asctime)s | %(client_addr)s - "%(request_line)s" %(status_code)s'
    use_colors: true

handlers:
  console:
    class: logging.StreamHandler
    formatter: default
    stream: ext://sys.stdout
  access:
    class: logging.StreamHandler
    formatter: access
    stream: ext://sys.stdout

root:
  level: INFO
  handlers: [console]

loggers:
  uvicorn.error:
    level: INFO

  uvicorn.access:
    level: INFO
    propagate: false
    handlers: [access]

Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR!

This seems to be a duplicate of #36 though, which also has tests. So I'll go ahead and close this one for now.

@svlandeg svlandeg closed this Mar 6, 2026
@regisin
Copy link
Author

regisin commented Mar 6, 2026

Oh yes, that looks much better, thanks for checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants