feat: add logging enhancements by integrating pino and pino-pretty for improved error tracking and debugging across the application
This commit is contained in:
34
src/lib/logger.ts
Normal file
34
src/lib/logger.ts
Normal 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;
|
||||
|
||||
Reference in New Issue
Block a user