feat: add structured JSON logging and metrics collection #15

Merged
ti-paul merged 1 commit from feature/10-monitoring-logging into main 2026-05-08 03:40:31 +00:00
Member

Summary

Adds production-ready monitoring infrastructure to pixel-clash.

New files

  • server/logger.js — Structured JSON logger (debug/info/warn/error), child context, LOG_LEVEL env var, stderr for errors
  • server/metrics.js — In-memory counters, gauges, histograms with snapshot API
  • server/logger.test.js — 5 unit tests
  • server/metrics.test.js — 10 unit tests

New endpoints

  • GET /api/health — Liveness check (uptime, memory, ws clients, board status)
  • GET /api/metrics — Full metrics snapshot (process info, all counters/gauges/histograms)

Changes

  • Replaced all console.log with structured logger.info/warn/error calls
  • Added request logging middleware (duration tracking, 5xx warnings)
  • Tracking: pixels placed, power pixels, registrations, sessions, WS connections
  • Added board.isLoaded() helper

Test results

15/15 tests passing
logger: 5 tests
metrics: 10 tests

Closes #10

## Summary Adds production-ready monitoring infrastructure to pixel-clash. ### New files - `server/logger.js` — Structured JSON logger (debug/info/warn/error), child context, LOG_LEVEL env var, stderr for errors - `server/metrics.js` — In-memory counters, gauges, histograms with snapshot API - `server/logger.test.js` — 5 unit tests - `server/metrics.test.js` — 10 unit tests ### New endpoints - `GET /api/health` — Liveness check (uptime, memory, ws clients, board status) - `GET /api/metrics` — Full metrics snapshot (process info, all counters/gauges/histograms) ### Changes - Replaced all `console.log` with structured `logger.info/warn/error` calls - Added request logging middleware (duration tracking, 5xx warnings) - Tracking: pixels placed, power pixels, registrations, sessions, WS connections - Added `board.isLoaded()` helper ### Test results ``` 15/15 tests passing logger: 5 tests metrics: 10 tests ``` Closes #10
feat: add structured JSON logging and metrics collection
All checks were successful
CI / test (pull_request) Successful in 17s
bc3bd3a68c
- Add logger.js: JSON structured logger with levels (debug/info/warn/error),
  child logger context merging, LOG_LEVEL env support, stderr for errors
- Add metrics.js: in-memory counters, gauges, and histograms
- Add /api/health endpoint for liveness checks
- Add /api/metrics endpoint for monitoring data (uptime, memory, ws clients,
  request counts, latency histograms)
- Add request logging middleware (duration tracking, 5xx warnings)
- Add metrics tracking for: pixels placed, power pixels, registrations,
  sessions, WS connections/disconnections, board fetches
- Add board.isLoaded() helper for health checks
- Replace console.log with structured logger throughout server
- Add 15 unit tests (logger: 5, metrics: 10) - all passing

Closes #10
ti-paul left a comment
No description provided.
LGTM - clean structured logging, good test coverage (15/15), no emoji in code. Metrics API looks solid.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
les_clankeurs/pixel-clash!15
No description provided.