feat(08-01): Health monitoring & logging infrastructure
- Set up Winston structured logging with console and file outputs - Create GET /api/health endpoint with uptime, database status, response times - Add request logging middleware (method, path, statusCode, duration) - Create health monitoring module with database connectivity checks - Log all HTTP requests with timing information - Log auth events (login, register) and data modifications - Replace console.log/error with structured logger calls - Update backend README with logging configuration documentation - Add tests for health endpoint and logging middleware - Logs directory: logs/combined.log and logs/error.log Deliverables met: ✓ Structured logging (Winston) integrated ✓ Enhanced health endpoint with uptime & database info ✓ Request logging middleware attached to all routes ✓ Comprehensive logging documentation in README.md ✓ Tests passing for health and logging functionality ✓ All critical operations logged with context
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
/**
|
||||
* Request Logging Middleware
|
||||
* Logs HTTP method, path, status code, and request duration
|
||||
*/
|
||||
function requestLoggerMiddleware(req, res, next) {
|
||||
const startTime = Date.now();
|
||||
const originalSend = res.send;
|
||||
|
||||
// Override send method to capture response
|
||||
res.send = function (data) {
|
||||
const duration = Date.now() - startTime;
|
||||
const statusCode = res.statusCode;
|
||||
|
||||
// Log request details
|
||||
logger.info('HTTP Request', {
|
||||
method: req.method,
|
||||
path: req.path,
|
||||
statusCode: statusCode,
|
||||
duration: `${duration}ms`,
|
||||
ip: req.ip,
|
||||
userAgent: req.get('user-agent')
|
||||
});
|
||||
|
||||
// Call original send method
|
||||
return originalSend.call(this, data);
|
||||
};
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = requestLoggerMiddleware;
|
||||
Reference in New Issue
Block a user