-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
75 lines (69 loc) · 1.78 KB
/
Copy pathlogger.js
File metadata and controls
75 lines (69 loc) · 1.78 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const winston = require("winston");
winston.emitErrs = true;
let transports = [];
if (process.env.LOGS === "DEV") {
transports.push(
new winston.transports.Console({
handleExceptions: true,
json: false,
colorize: true
})
);
} else if (process.env.LOGS === "ALL_FILES") {
transports.push(
new winston.transports.File({
filename: "./logs/all.log",
level: "debug",
handleExceptions: true,
json: true,
maxsize: 5242880,
maxFiles: 3,
colorize: false,
timestamp: function() {
//5MB
return new Date().toISOString();
}
})
);
} else {
transports.push(
new winston.transports.File({
name: "error-file",
level: "error",
filename: "./logs/error.log",
handleExceptions: true,
json: true,
maxsize: 5242880, //5MB
maxFiles: 3,
colorize: false,
timestamp: function() {
return new Date().toISOString();
}
})
);
transports.push(
new winston.transports.File({
name: "warning-file",
level: "warn",
filename: "./logs/warning.log",
handleExceptions: true,
json: true,
maxsize: 5242880, //5MB
maxFiles: 3,
colorize: false,
timestamp: function() {
return new Date().toISOString();
}
})
);
}
const logger = new winston.Logger({
transports,
exitOnError: false
});
logger.stream = {
write: function(message, encoding) {
logger.info(message);
}
};
module.exports = logger;