Logging: add informative console logs for startup, ports, connections, JOIN/deny, input, and periodic events

- Configure logging via LOG_LEVEL env (default INFO)
- Log when servers start listening (WT/QUIC/InMemory/HTTPS static)
- Log WT CONNECT accept, QUIC peer connect, datagram traffic at DEBUG
- Log GameServer creation, tick loop start, JOIN accept/deny, config_update broadcasts, and input reception
This commit is contained in:
Vladyslav Doloman
2025-10-08 00:01:05 +03:00
parent c97c5c4723
commit eeabda725e
6 changed files with 30 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ from dataclasses import dataclass
from typing import Awaitable, Callable, Dict, Optional
from .transport import DatagramServerTransport, OnDatagram, TransportPeer
import logging
try:
@@ -49,6 +50,7 @@ class GameWTProtocol(QuicConnectionProtocol): # type: ignore[misc]
# In WebTransport over H3, datagrams use the CONNECT stream id as flow_id
flow_id = event.stream_id # type: ignore[attr-defined]
self._sessions[flow_id] = WTSession(flow_id=flow_id, proto=self)
logging.info("WT CONNECT accepted: flow_id=%s", flow_id)
# Send 2xx to accept the session
if self._http is not None:
self._http.send_headers(event.stream_id, [(b":status", b"200")])
@@ -62,6 +64,7 @@ class GameWTProtocol(QuicConnectionProtocol): # type: ignore[misc]
if not sess:
return
peer = TransportPeer(addr=(self, flow_id))
logging.debug("WT datagram received: flow_id=%s, %d bytes", flow_id, len(data))
asyncio.ensure_future(self._on_datagram(bytes(data), peer))
def quic_event_received(self, event) -> None: # type: ignore[override]
@@ -79,6 +82,7 @@ class GameWTProtocol(QuicConnectionProtocol): # type: ignore[misc]
if self._http is None:
return
try:
logging.debug("WT send datagram: flow_id=%s, %d bytes", flow_id, len(data))
self._http.send_datagram(flow_id, data)
await self._loop.run_in_executor(None, self.transmit) # type: ignore[attr-defined]
except Exception:
@@ -117,9 +121,9 @@ class WebTransportServer(DatagramServerTransport):
async def _create_protocol(*args, **kwargs):
return GameWTProtocol(*args, on_datagram=self._on_datagram, sessions=self._sessions, **kwargs)
logging.info("WebTransport (H3) server listening on %s:%d", self.host, self.port)
self._server = await serve(self.host, self.port, configuration=configuration, create_protocol=_create_protocol)
try:
await self._server.wait_closed()
finally:
self._server.close()