Skip to content

Commit

Permalink
server logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Jan 9, 2025
1 parent dcccf39 commit 731a83e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions nightwatch/rics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."}})

Expand All @@ -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"})
Expand All @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions nightwatch/rics/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 731a83e

Please sign in to comment.