Logging config based on default uvicorn settings
This commit is contained in:
parent
4ef74c42c3
commit
c919f8a19f
1 changed files with 8 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
from labthings_fastapi.server import cli, ThingServer
|
from labthings_fastapi.server import cli, ThingServer
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
@ -23,6 +24,11 @@ def customise_server(server: ThingServer, log_folder: str):
|
||||||
def serve_from_cli(argv: Optional[list[str]] = None):
|
def serve_from_cli(argv: Optional[list[str]] = None):
|
||||||
"""Start the server from the command line"""
|
"""Start the server from the command line"""
|
||||||
args = cli.parse_args(argv)
|
args = cli.parse_args(argv)
|
||||||
|
|
||||||
|
log_config = copy(uvicorn.config.LOGGING_CONFIG)
|
||||||
|
log_config["loggers"]["uvicorn"]["propagate"] = True
|
||||||
|
log_config["loggers"]["uvicorn.access"]["propagate"] = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = cli.config_from_args(args)
|
config = cli.config_from_args(args)
|
||||||
log_folder = config.get("log_folder", "./openflexure/logs")
|
log_folder = config.get("log_folder", "./openflexure/logs")
|
||||||
|
|
@ -32,10 +38,7 @@ def serve_from_cli(argv: Optional[list[str]] = None):
|
||||||
server.app,
|
server.app,
|
||||||
host=args.host,
|
host=args.host,
|
||||||
port=args.port,
|
port=args.port,
|
||||||
log_config={
|
log_config=log_config,
|
||||||
"version": 1,
|
|
||||||
"disable_existing_loggers": False,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
|
|
@ -51,10 +54,7 @@ def serve_from_cli(argv: Optional[list[str]] = None):
|
||||||
app,
|
app,
|
||||||
host=args.host,
|
host=args.host,
|
||||||
port=args.port,
|
port=args.port,
|
||||||
log_config={
|
log_config=log_config,
|
||||||
"version": 1,
|
|
||||||
"disable_existing_loggers": False,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue