Skip to content

Commit

Permalink
Implement --log-config for all server CLI commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Apr 25, 2024
1 parent ebebe51 commit 364b0d1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tiled/commandline/_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def serve_directory(
from ..client import from_uri as client_from_uri

print_admin_api_key_if_generated(web_app, host=host, port=port, force=generated)
config = uvicorn.Config(web_app, host=host, port=port)
config = uvicorn.Config(web_app, host=host, port=port, log_config=log_config)
server = uvicorn.Server(config)

async def run_server():
Expand Down Expand Up @@ -334,6 +334,9 @@ def serve_catalog(
"This verifies that the configuration is compatible with scaled (multi-process) deployments."
),
),
log_config: Optional[str] = typer.Option(
None, help="Custom uvicorn logging configuration file"
),
):
"Serve a catalog."
import urllib.parse
Expand Down Expand Up @@ -433,7 +436,7 @@ def serve_catalog(

import uvicorn

uvicorn.run(web_app, host=host, port=port)
uvicorn.run(web_app, host=host, port=port, log_config=log_config)


serve_app.command("catalog")(serve_catalog)
Expand Down Expand Up @@ -477,6 +480,9 @@ def serve_pyobject(
"This verifies that the configuration is compatible with scaled (multi-process) deployments."
),
),
log_config: Optional[str] = typer.Option(
None, help="Custom uvicorn logging configuration file"
),
):
"Serve a Tree instance from a Python module."
from ..server.app import build_app, print_admin_api_key_if_generated
Expand All @@ -497,7 +503,7 @@ def serve_pyobject(

import uvicorn

uvicorn.run(web_app, host=host, port=port)
uvicorn.run(web_app, host=host, port=port, log_config=log_config)


@serve_app.command("demo")
Expand Down Expand Up @@ -571,6 +577,9 @@ def serve_config(
"This verifies that the configuration is compatible with scaled (multi-process) deployments."
),
),
log_config: Optional[str] = typer.Option(
None, help="Custom uvicorn logging configuration file"
),
):
"Serve a Tree as specified in configuration file(s)."
import os
Expand Down Expand Up @@ -605,9 +614,10 @@ def serve_config(

# Extract config for uvicorn.
uvicorn_kwargs = parsed_config.pop("uvicorn", {})
# If --host is given, it overrides host in config. Same for --port.
# If --host is given, it overrides host in config. Same for --port and --log-config.
uvicorn_kwargs["host"] = host or uvicorn_kwargs.get("host", "127.0.0.1")
uvicorn_kwargs["port"] = port or uvicorn_kwargs.get("port", 8000)
uvicorn_kwargs["log_config"] = log_config or uvicorn_kwargs.get("log_config")

# This config was already validated when it was parsed. Do not re-validate.
logger.info(f"Using configuration from {Path(config_path).absolute()}")
Expand Down

0 comments on commit 364b0d1

Please sign in to comment.