-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
42 lines (37 loc) · 1.01 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
'use strict';
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, printf, colorize } = format;
require('winston-daily-rotate-file');
const formatArg = args =>
args.map(arg => arg.stack || JSON.stringify(arg)).join('\n');
const myFormat = printf(({ level, message, time, args }) =>
`${time} ${level} ${message} ${formatArg(args)}`);
const logger = createLogger({
level: 'info',
format: combine(
timestamp(),
myFormat
),
transports: [
new transports.Console({
format: combine(
colorize(),
timestamp(),
myFormat
)
}),
new transports.DailyRotateFile({
filename: 'teslapizero.log',
frequency: '1w',
maxSize: '1m',
maxFiles: 2,
auditFile: 'log-audit.json'
})
],
colorize: true
});
module.exports = {
error: (message, ...args) => logger.error(message, { args }),
warn: (message, ...args) => logger.warn(message, { args }),
info: (message, ...args) => logger.info(message, { args }),
};