Skip to content

Enhance logging across client, server, and ARQ layers#61

Open
mmdrn wants to merge 1 commit intomasterking32:mainfrom
mmdrn:main
Open

Enhance logging across client, server, and ARQ layers#61
mmdrn wants to merge 1 commit intomasterking32:mainfrom
mmdrn:main

Conversation

@mmdrn
Copy link

@mmdrn mmdrn commented Mar 25, 2026

Summary

This PR adds comprehensive, structured logging throughout the VPN system to improve operational observability and debugging.

Logger Enhancement

  • Added SubLogger type with With(key, value) chaining for automatic context propagation (e.g., [Sess:3] [Str:42])
  • Added Warnf to the ARQ Logger interface

Session Lifecycle Logging

  • Log session accepted with ID, cookie, and compression mode (INFO)
  • Log session init failures, server busy, query build errors (WARN/DEBUG)
  • Log rejected session close notices on server side (DEBUG)

Stream Lifecycle Logging

  • Log stream creation with stream/session IDs (INFO)
  • Log stream cleanup (DEBUG) and bulk close with count (INFO)
  • Log server-side stream creation (DEBUG)
  • Elevated SOCKS connected to INFO, added SOCKS failure logging (WARN)

Silent Error Elimination

  • DNS response write failures in dns_listener.go (WARN)
  • SOCKS handshake errors and unknown versions (DEBUG)
  • Dispatcher encode/build failures (DEBUG) and no-valid-connections (WARN)
  • Session close query build failures (DEBUG)
  • Server buildNoDataResponseLogged now actually logs the reason (DEBUG)

Periodic Stats Reporting

  • Client: 30s ticker logging active/pending/draining streams, valid resolvers, and per-resolver sent/acked/loss%/RTT
  • Server: 30s ticker logging active sessions and total streams
  • Added Balancer.Stats() method for aggregate connection statistics

ARQ Logging

  • Data retransmissions with sequence number (DEBUG)
  • Max retransmissions exceeded (WARN)
  • Inactivity timeout with idle duration (INFO)
  • Control packet expiry and retransmissions (DEBUG)

Design Decisions

  • No external dependencies added — extends the existing custom logger
  • No per-packet logging in hot paths to avoid performance impact
  • Keeps the project's emoji/color tag style
  • SubLogger satisfies the ARQ Logger interface for seamless integration

Files Changed (16)

  • internal/logger/logger.go — SubLogger type
  • internal/logger/logger_test.go — 4 new tests
  • internal/arq/arq.go — Warnf interface + 5 log points
  • internal/arq/arq_test.go — testLogger updated
  • internal/client/session.go — session lifecycle logs
  • internal/client/stream_client.go — stream lifecycle logs
  • internal/client/socks_manager.go — SOCKS result logs
  • internal/client/async_runtime.go — periodic stats logger
  • internal/client/balancer.go — Stats() method
  • internal/client/dispatcher.go — error path logs
  • internal/client/dns_listener.go — write error log
  • internal/client/tcp_listener.go — unsupported protocol log
  • internal/udpserver/server.go — server stats logger
  • internal/udpserver/server_session.go — close rejection log
  • internal/udpserver/server_utils.go — NoData reason log
  • internal/udpserver/stream_server.go — stream creation log

Testing

  • All existing tests pass
  • 4 new logger tests added (prefix, chaining, level filtering, Enabled)
  • go build ./... clean

@mmdrn
Copy link
Author

mmdrn commented Mar 25, 2026

@masterking32 Please review this PR.

Add SubLogger with context fields (session/stream IDs), session and stream
lifecycle logs, silent error elimination, periodic stats reporting, and
ARQ retransmit/timeout logging.
@mmdrn
Copy link
Author

mmdrn commented Mar 26, 2026

@masterking32 Conflicts resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant