-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.js
39 lines (32 loc) · 877 Bytes
/
logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pino from 'pino';
const destination =
process.env.LOG_HANDLER === 'file'
? pino.destination(
`/var/log/marketo-middleware/app-${process.env.APP_ID}.log`
)
: pino.destination(1); // STDOUT
const pinoLogger = pino(
{
name: process.env.APP_ID,
level: process.env.LOG_LEVEL || 'info',
},
destination
);
process.on(
'uncaughtException',
(err) => {
pinoLogger.error(err, 'uncaughtException');
process.exit(1); // eslint-disable-line no-process-exit
}
);
process.on(
'unhandledRejection',
(err) => {
pinoLogger.error(err, 'unhandledRejection');
process.exit(1); // eslint-disable-line no-process-exit
}
);
// Reopen the destination after logrotate does it's magic!
process.on('SIGUSR2', () => destination.reopen());
export const appLogger = pinoLogger.child({ logger: 'app' });
export default pinoLogger;