-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlogger.js
27 lines (25 loc) · 935 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
const { createLogger, format, transports } = require('winston');
const path = require('path');
const logDir = "logs";
const logger = caller => {
return createLogger(
{
transports: [
new transports.Console({level: "debug", colorize: true}),
new transports.File({
filename: path.join(logDir, "output.log"),
level: "debug"
}),
new transports.File({
filename: path.join(logDir, "error.log"),
level: "error"
})
],
format: format.combine(
format.label({label: path.basename(caller)}),
format.timestamp({format: "YYYY-MM-DD HH:mm:ss"}),
format.printf(info => `[${info.timestamp}] [${info.label}] [${info.level}]: ${info.message}`)
)
});
};
module.exports = logger;