forked from q2ebanking/team-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
45 lines (41 loc) · 1.08 KB
/
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
const chalk = require('chalk')
const { createLogger, format, transports } = require('winston')
require('winston-daily-rotate-file')
const { combine, timestamp, printf, colorize } = format
const logger = createLogger()
const _init = (logPath) => {
logger.configure({
level: process.env.LOG_LEVEL || 'info',
format: format.combine(
timestamp(),
printf(info => `${info.timestamp} [${info.level}]: ${info.message}`),
),
transports: [
new transports.DailyRotateFile({
filename: 'error-%DATE%.log',
dirname: logPath,
level: 'error',
maxFiles: '10d',
}),
new transports.DailyRotateFile({
filename: 'combined-%DATE%.log',
dirname: logPath,
maxFiles: '10d',
}),
],
})
logger.add(new transports.Console({
format: combine(
colorize(),
printf(info => `[${info.level}] ${info.message}`)
),
}))
}
const consoleTip = (...logItems) => {
console.log(chalk.yellow(logItems))
}
module.exports = {
_init,
logger,
consoleTip,
}