'How write logs to file with unicorn config
Its my uvicorn log_config.yaml
. All works perfect untill i add logging to file. Its says to me
ValueError: not enough values to unpack (expected 5, got 0)
I try different variations of logging (FileHandler
,RotateHandler
) but same issue raised.
version: 1
disable_existing_loggers: False
formatters:
default:
"()": uvicorn.logging.DefaultFormatter
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
access:
"()": uvicorn.logging.AccessFormatter
format: "[%(asctime)s %(process)d:%(threadName)s] %(name)s - %(levelname)s - %(message)s | %(filename)s:%(lineno)d"
handlers:
default:
formatter: default
class: logging.StreamHandler
stream: ext://sys.stderr
access:
formatter: access
class: logging.StreamHandler
stream: ext://sys.stdout
file_handler:
class: logging.FileHandler
level: INFO
formatter: access
filename: info.log
encoding: utf8
mode: a
loggers:
uvicorn.error:
level: INFO
handlers: [default]
propagate: no
uvicorn.access:
level: INFO
handlers: [access]
propagate: no
Solution 1:[1]
Since you specified all information about formatter in the yaml
file you have no formatter object.
The python class for logging.FileHandler
does not have an argument called formatter
and thus custom formats cannot be used.
https://docs.python.org/3/library/logging.handlers.html#logging.FileHandler
Saying this, you can use the formatter: default
as it's registered being the DefaultFormatter
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |