Skip to content

BE06 logging system_Vedant#206

Merged
TienNguyen3711 merged 2 commits intomasterfrom
BE06-Logging-System
Apr 2, 2026
Merged

BE06 logging system_Vedant#206
TienNguyen3711 merged 2 commits intomasterfrom
BE06-Logging-System

Conversation

@Vedant1515
Copy link
Copy Markdown
Collaborator

Overview
Implemented centralized structured logging across the NutriHelp API backend to improve traceability, observability, and production debugging.

New Files

utils/logger.js – Centralized Winston-based structured logger (163 lines)
middleware/requestLogger.js – HTTP request/response logging middleware (83 lines)
middleware/structuredErrorHandler.js – Structured error handling middleware (79 lines)

Modified Files

server.js – Integrated request logger and error handler middleware
package.json – Added Winston dependency
10 controllers updated: authController, appointmentController, chatbotController, homeServiceController, imageClassificationController, loginController, medicalPredictionController, notificationController, uploadController, userPreferencesController

Changes

Every HTTP request logged with timestamp, method, endpoint, status code, and duration
Errors captured in consistent structured format with stack traces where appropriate
Environment-aware logging, readable in dev, concise and structured in production
Replaced unstructured console.log calls across all major controllers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be stronger if we enforced a more consistent schema across all logs, especially fields like requestId, endpoint, method, and statusCode.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d recommend also returning the requestId in a response header and ensuring downstream services consistently include it in their logs for end-to-end traceability

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It currently overlaps with errorLogService. It would be better to consolidate on a single structured logging path so error logs do not end up split across different formats.

@TienNguyen3711
Copy link
Copy Markdown
Collaborator

Please resolve the merge conflict.

@TienNguyen3711 TienNguyen3711 merged commit c7a80ee into master Apr 2, 2026
9 checks passed
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.

2 participants