Logging Update - IPadress & user Email if possible

This commit is contained in:
2024-09-23 13:45:46 +02:00
parent 974a6503ef
commit 1282d30b49
16 changed files with 163 additions and 22 deletions

View File

@@ -20,21 +20,22 @@ export class RequestDurationMiddleware implements NestMiddleware {
this.logger.error('Failed to set CLS context', error);
}
const start = Date.now();
// const start = Date.now();
this.logger.log(`Entering ${req.method} ${req.originalUrl} from ${ip}`);
// this.logger.log(`Entering ${req.method} ${req.originalUrl} from ${ip}`);
res.on('finish', () => {
const duration = Date.now() - start;
let logMessage = `${req.method} ${req.originalUrl} - ${duration}ms - IP: ${ip}`;
// res.on('finish', () => {
// const duration = Date.now() - start;
// const userEmail = this.cls.get('userEmail') || 'unknown';
// let logMessage = `${req.method} ${req.originalUrl} - ${duration}ms - IP: ${ip} - User: ${userEmail}`;
if (req.method === 'POST' || req.method === 'PUT') {
const body = JSON.stringify(req.body);
logMessage += ` - Incoming Body: ${body}`;
}
// if (req.method === 'POST' || req.method === 'PUT') {
// const body = JSON.stringify(req.body);
// logMessage += ` - Incoming Body: ${body}`;
// }
this.logger.log(logMessage);
});
// this.logger.log(logMessage);
// });
next();
}