Skip to content

feat(logging): implement structured logging system (#560)#1

Open
fytgian wants to merge 1 commit into
mainfrom
feature/560-logging-system
Open

feat(logging): implement structured logging system (#560)#1
fytgian wants to merge 1 commit into
mainfrom
feature/560-logging-system

Conversation

@fytgian

@fytgian fytgian commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

Closes Vera3289#560

Implements a comprehensive structured logging system using Winston with multiple transports, daily file rotation, and request tracing.

Changes

New files

  • api/services/logger.js — Winston logger singleton with JSON format, daily rotating transports (all-levels + error-only), configurable log level, and logger.forRequest(req) / logger.perf() helpers
  • api/middleware/requestLogger.js — Express middleware that logs every request/response with duration, status, method, URL, and IP; attaches req.log child logger (correlationId-bound) for use inside route handlers

Modified files

  • api/middleware/errorHandler.js — replaced console.error with structured logger.error including full stack trace
  • api/server.js — wired requestLogger middleware after correlationId; replaced all console.log / console.error calls with logger

Acceptance Criteria

Criterion Status
Structured JSON logging winston.format.json() on all file transports
Log levels (debug/info/warn/error) ✅ Configurable via LOG_LEVEL env var
File rotation winston-daily-rotate-file: 20 MB max, 14-day retention (errors 30-day), gzip
Request ID tracking correlationId bound to every log via child logger
Performance metrics logging logger.perf(operation, durationMs) called on every HTTP response
Error stack traces winston.format.errors({ stack: true }) + full stack in errorHandler
ELK-ready ✅ JSON format on file transports, compatible with Filebeat/Logstash

Configuration

Env var Default Description
LOG_LEVEL debug (dev) / info (prod) Minimum log level
LOG_DIR api/logs/ Directory for rotating log files

- Add Winston logger with JSON format and multiple transports
- Daily rotating file logs (all levels + error-only), gzip compressed, 14/30-day retention
- Console transport with colorized dev output and JSON in production
- requestLogger middleware: structured request/response logs with duration
- Per-request child logger via req.log (correlationId bound automatically)
- logger.perf() helper for performance metric logging
- Error stack traces logged via winston errors() format
- Replace all console.log/error in server.js and errorHandler with logger
- Log level configurable via LOG_LEVEL env var
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.

Create Logging System

1 participant