Skip to content

Commit

Permalink
Merge pull request #9062 from OpenMined/aziz/uvicorn_logs
Browse files Browse the repository at this point in the history
set log level to critical if not in dev mode
  • Loading branch information
abyesilyurt authored Jul 18, 2024
2 parents 1b04d4e + cb84814 commit 4293519
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/syft/src/syft/server/uvicorn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# stdlib
from collections.abc import Callable
import logging
import multiprocessing
import multiprocessing.synchronize
import os
Expand Down Expand Up @@ -122,7 +123,8 @@ def run_uvicorn(
starting_uvicorn_event: multiprocessing.synchronize.Event,
**kwargs: Any,
) -> None:
should_reset = kwargs.get("dev_mode") and kwargs.get("reset")
dev_mode = kwargs.get("dev_mode")
should_reset = dev_mode and kwargs.get("reset")

if should_reset:
print("Found `reset=True` in the launch configuration. Resetting the server...")
Expand All @@ -140,6 +142,12 @@ def run_uvicorn(
except Exception: # nosec
print(f"Failed to kill python process on port: {port}")

log_level = "critical"
if dev_mode:
log_level = "info"
logging.getLogger("uvicorn").setLevel(logging.CRITICAL)
logging.getLogger("uvicorn.access").setLevel(logging.CRITICAL)

if kwargs.get("debug"):
attach_debugger()

Expand All @@ -166,8 +174,9 @@ def run_uvicorn(
host=host,
port=port,
factory=True,
reload=kwargs.get("dev_mode"),
reload_dirs=[Path(__file__).parent.parent] if kwargs.get("dev_mode") else None,
reload=dev_mode,
reload_dirs=[Path(__file__).parent.parent] if dev_mode else None,
log_level=log_level,
)


Expand Down

0 comments on commit 4293519

Please sign in to comment.