Skip to content

Commit 731a83e

Browse files
committed
server logging improvements
1 parent dcccf39 commit 731a83e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ Configuration is available at:
6363
- ***nix systems**: ~/.config/nightwatch
6464
- **Windows**: %LocalAppData%\Nightwatch
6565

66-
Client (terminal) configuration is available at `client.json`, while the server configuration is stored in `server.json`.
66+
Client (terminal) configuration is available at `client.json`, while the server configuration is stored in `rics.json`.
6767
The Nightwatch client uses the JSON for username, coloring, and more. Check the `/config` command for more information.
6868
The backend chat server uses the config file for the server name, although more is sure to come.

nightwatch/rics/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ async def connect_endpoint(
173173
}})
174174

175175
# Broadcast join
176+
log.info("ws", f"{client.username} has joined the server.")
176177
await app.state.broadcast({"type": "join", "data": {"user": client.serialize()}})
177178
await app.state.broadcast({"type": "message", "data": {"message": f"{client.username} has joined the server."}})
178179

@@ -184,6 +185,7 @@ async def connect_endpoint(
184185
await client.send({"type": "problem", "data": {"message": "You cannot send a blank message."}})
185186
continue
186187

188+
log.info("ws", f"{client.username}: {message}")
187189
await app.state.broadcast({"type": "message", "data": {"user": client.serialize(), "message": message}})
188190
if client._callback is not None:
189191
await client.send({"type": "response"})
@@ -202,6 +204,7 @@ async def connect_endpoint(
202204
client.cleanup()
203205
await app.state.broadcast({"type": "leave", "data": {"user": client.serialize()}})
204206
await app.state.broadcast({"type": "message", "data": {"message": f"{client.username} has left the server."}})
207+
log.info("ws", f"{client.username} has left the server.")
205208

206209
@app.get("/api/version")
207210
async def route_version() -> JSONResponse:

nightwatch/rics/__main__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
import sys
77

88
import uvicorn
9+
from nightwatch.logging import log
910

1011
# Launch uvicorn
12+
host = os.getenv("HOST", "127.0.0.1")
13+
port = int(os.getenv("PORT") or 8000)
14+
log.info("http", f"Running on {host}:{port}!")
15+
1116
uvicorn.run(
1217
"nightwatch.rics:app", # Allow debug reloading,
13-
host = os.getenv("HOST", "127.0.0.1"),
14-
port = int(os.getenv("PORT") or 8000),
15-
# log_level = "critical", # Soon! when i have a better idea for logging requests
18+
host = host,
19+
port = port,
20+
log_level = "critical",
1621
reload = "--dev" in sys.argv
1722
)

0 commit comments

Comments
 (0)