feat(logging): implement structured logging system (#560)#1
Open
fytgian wants to merge 1 commit into
Open
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andlogger.forRequest(req)/logger.perf()helpersapi/middleware/requestLogger.js— Express middleware that logs every request/response with duration, status, method, URL, and IP; attachesreq.logchild logger (correlationId-bound) for use inside route handlersModified files
api/middleware/errorHandler.js— replacedconsole.errorwith structuredlogger.errorincluding full stack traceapi/server.js— wiredrequestLoggermiddleware aftercorrelationId; replaced allconsole.log/console.errorcalls withloggerAcceptance Criteria
winston.format.json()on all file transportsLOG_LEVELenv varwinston-daily-rotate-file: 20 MB max, 14-day retention (errors 30-day), gzipcorrelationIdbound to every log via child loggerlogger.perf(operation, durationMs)called on every HTTP responsewinston.format.errors({ stack: true })+ full stack in errorHandlerConfiguration
LOG_LEVELdebug(dev) /info(prod)LOG_DIRapi/logs/