-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggerProject.js
40 lines (32 loc) · 1.04 KB
/
loggerProject.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
const {createLogger,transports,format } = require('winston');
const moment = require('moment');
const customFormat = format.combine(format.timestamp(),format.printf((info)=>{
return `${info.timestamp} - [${info.level.toUpperCase().padEnd(7)}] - ${info.message}`
}))
const currentDateTime = moment().format('YYYY-MM-DD_HH-mm-ss');
let projectName = process.argv[2] || 'chipsterProject';
let transportsArr = [
new transports.Console({
level:"silly"
}),
new transports.File({
filename:`../Projects/${projectName}/logs/project-${currentDateTime}-debug.log`,
level: 'debug',
maxsize: 10485760
}),
new transports.File({
filename:`../Projects/${projectName}/logs/project-${currentDateTime}-info.log`,
level: 'info',
maxsize: 10485760
}),
new transports.File({
filename:`../Projects/${projectName}/logs/project-${currentDateTime}-error.log`,
level: 'error',
maxsize: 10485760
})
]
const logger = createLogger({
format:customFormat,
transports:transportsArr
});
module.exports = logger;