-
-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathlogger.js
More file actions
31 lines (25 loc) · 706 Bytes
/
Copy pathlogger.js
File metadata and controls
31 lines (25 loc) · 706 Bytes
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
import path from 'node:path'
import bunyan from 'bunyan'
const isRunningTests = process.env.npm_lifecycle_event === 'test'
const stdoutLevel = isRunningTests ? 'FATAL' : process.env.LOG_LEVEL || 'INFO'
const daysToKeepLogs = process.env.KEEP_LOGS || 10
const logsDir = process.env.LOGS_DIR || ''
const rotatingFilePath = path.join(logsDir, 'bot.log')
const streams = [{
stream: process.stdout,
level: stdoutLevel
}]
// write to file when $LOGS_DIR is set
if (logsDir) {
streams.push({
type: 'rotating-file',
path: rotatingFilePath,
period: '1d', // daily rotation
count: daysToKeepLogs,
level: 'debug'
})
}
export default bunyan.createLogger({
name: 'bot',
streams
})