-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
52 lines (46 loc) · 993 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
40
41
42
43
44
45
46
47
48
49
50
51
52
const pino = require('pino')
const path = require('path')
const {
LOG_LEVEL,
ENABLE_LOGGING,
MAX_LOGS,
LOGGER_VERBOSE,
} = require('@src/config')
const levels = {
crit: 60,
error: 50,
warn: 40,
info: 20,
}
const rotatingLogStream = require('file-stream-rotator').getStream({
filename: path.join(__dirname, '/logs/app-%DATE%'),
frequency: 'daily',
extension: '.log',
max_logs: MAX_LOGS,
date_format: 'YYYYMMDD',
verbose: LOGGER_VERBOSE,
})
const streams = Object.keys(levels).map((level) => {
return {
level,
stream: rotatingLogStream,
}
})
const logger = pino(
{
level: LOG_LEVEL,
customLevels: levels,
useOnlyCustomLevels: true,
formatters: {
level: (label) => {
return { level: label }
},
},
enabled: ENABLE_LOGGING,
},
pino.multistream(streams, { levels, dedupe: true })
)
const logs = (level, methodName, message) => {
logger[level](`${methodName} - ${message}`)
}
module.exports = { logs }