feat: add logging enhancements by integrating pino and pino-pretty for improved error tracking and debugging across the application

This commit is contained in:
Julien Froidefond
2025-10-26 06:15:47 +01:00
parent 7cc72dc13d
commit 52350a43d9
84 changed files with 455 additions and 177 deletions

34
src/lib/logger.ts Normal file
View File

@@ -0,0 +1,34 @@
import pino from 'pino';
const isProduction = process.env.NODE_ENV === 'production';
const logger = pino({
level: isProduction ? 'info' : 'debug',
...(isProduction
? {}
: {
transport: {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'SYS:dd/mm/yyyy HH:MM:ss',
ignore: 'pid,hostname',
singleLine: true,
},
},
}),
formatters: {
level: (label) => {
return { level: label.toUpperCase() };
},
},
});
// Prevent memory leaks in development (Node.js runtime only)
if (!isProduction && typeof process.stdout !== 'undefined') {
process.stdout.setMaxListeners?.(20);
process.stderr.setMaxListeners?.(20);
}
export default logger;