mirror of
https://github.com/open-webui/mcpo.git
synced 2026-07-01 21:04:00 -04:00
Merge pull request #259 from diseku/feat/adjustable_log_level
feat: make log level adjustable
This commit is contained in:
@@ -69,6 +69,9 @@ def main(
|
||||
hot_reload: Annotated[
|
||||
Optional[bool], typer.Option("--hot-reload", help="Enable hot reload for config file changes")
|
||||
] = False,
|
||||
log_level: Annotated[
|
||||
Optional[str], typer.Option("--log-level", help="Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)")
|
||||
] = None,
|
||||
):
|
||||
server_command = None
|
||||
if not config_path:
|
||||
@@ -122,6 +125,10 @@ def main(
|
||||
if not path_prefix.startswith("/"):
|
||||
path_prefix = f"/{path_prefix}"
|
||||
|
||||
# Set LOG_LEVEL environment variable if provided
|
||||
if log_level:
|
||||
os.environ["LOG_LEVEL"] = log_level
|
||||
|
||||
# Run your async run function from mcpo.main
|
||||
asyncio.run(
|
||||
run(
|
||||
|
||||
+14
-3
@@ -507,9 +507,18 @@ async def run(
|
||||
ssl_keyfile = kwargs.get("ssl_keyfile")
|
||||
path_prefix = kwargs.get("path_prefix") or "/"
|
||||
|
||||
# Configure basic logging
|
||||
# Configure logging based on LOG_LEVEL environment variable
|
||||
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
|
||||
try:
|
||||
numeric_level = getattr(logging, log_level, None)
|
||||
if not isinstance(numeric_level, int):
|
||||
raise ValueError(f"Invalid log level: {log_level}")
|
||||
except (ValueError, AttributeError):
|
||||
logger.warning(f"Invalid LOG_LEVEL '{log_level}', defaulting to INFO")
|
||||
numeric_level = logging.INFO
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
||||
level=numeric_level, format="%(asctime)s - %(levelname)s - %(message)s"
|
||||
)
|
||||
|
||||
# Suppress HTTP request logs
|
||||
@@ -631,13 +640,15 @@ async def run(
|
||||
config_watcher.start()
|
||||
|
||||
logger.info("Uvicorn server starting...")
|
||||
uvicorn_log_level = log_level.lower()
|
||||
|
||||
config = uvicorn.Config(
|
||||
app=main_app,
|
||||
host=host,
|
||||
port=port,
|
||||
ssl_certfile=ssl_certfile,
|
||||
ssl_keyfile=ssl_keyfile,
|
||||
log_level="info",
|
||||
log_level=uvicorn_log_level,
|
||||
)
|
||||
server = uvicorn.Server(config)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user