From 731a83e45fefee190e264726f5a10795aee95b63 Mon Sep 17 00:00:00 2001 From: iiPython Date: Thu, 9 Jan 2025 15:04:43 -0600 Subject: [PATCH] server logging improvements --- README.md | 2 +- nightwatch/rics/__init__.py | 3 +++ nightwatch/rics/__main__.py | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3c0d6bb..58a0127 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,6 @@ Configuration is available at: - ***nix systems**: ~/.config/nightwatch - **Windows**: %LocalAppData%\Nightwatch -Client (terminal) configuration is available at `client.json`, while the server configuration is stored in `server.json`. +Client (terminal) configuration is available at `client.json`, while the server configuration is stored in `rics.json`. The Nightwatch client uses the JSON for username, coloring, and more. Check the `/config` command for more information. The backend chat server uses the config file for the server name, although more is sure to come. diff --git a/nightwatch/rics/__init__.py b/nightwatch/rics/__init__.py index 0260fdc..8952572 100644 --- a/nightwatch/rics/__init__.py +++ b/nightwatch/rics/__init__.py @@ -173,6 +173,7 @@ async def connect_endpoint( }}) # Broadcast join + log.info("ws", f"{client.username} has joined the server.") await app.state.broadcast({"type": "join", "data": {"user": client.serialize()}}) await app.state.broadcast({"type": "message", "data": {"message": f"{client.username} has joined the server."}}) @@ -184,6 +185,7 @@ async def connect_endpoint( await client.send({"type": "problem", "data": {"message": "You cannot send a blank message."}}) continue + log.info("ws", f"{client.username}: {message}") await app.state.broadcast({"type": "message", "data": {"user": client.serialize(), "message": message}}) if client._callback is not None: await client.send({"type": "response"}) @@ -202,6 +204,7 @@ async def connect_endpoint( client.cleanup() await app.state.broadcast({"type": "leave", "data": {"user": client.serialize()}}) await app.state.broadcast({"type": "message", "data": {"message": f"{client.username} has left the server."}}) + log.info("ws", f"{client.username} has left the server.") @app.get("/api/version") async def route_version() -> JSONResponse: diff --git a/nightwatch/rics/__main__.py b/nightwatch/rics/__main__.py index fef1872..8b13172 100644 --- a/nightwatch/rics/__main__.py +++ b/nightwatch/rics/__main__.py @@ -6,12 +6,17 @@ import sys import uvicorn +from nightwatch.logging import log # Launch uvicorn +host = os.getenv("HOST", "127.0.0.1") +port = int(os.getenv("PORT") or 8000) +log.info("http", f"Running on {host}:{port}!") + uvicorn.run( "nightwatch.rics:app", # Allow debug reloading, - host = os.getenv("HOST", "127.0.0.1"), - port = int(os.getenv("PORT") or 8000), - # log_level = "critical", # Soon! when i have a better idea for logging requests + host = host, + port = port, + log_level = "critical", reload = "--dev" in sys.argv )