-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogger.js
More file actions
48 lines (44 loc) · 1.2 KB
/
logger.js
File metadata and controls
48 lines (44 loc) · 1.2 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
import winston from 'winston';
import jsonStringify from "fast-safe-stringify";
const logLikeFormat = {
transform(info) {
const { timestamp, message } = info;
const level = info[Symbol.for('level')];
const args = info[Symbol.for('splat')];
const strArgs = args ? args.map(jsonStringify).join(' ') : '';
info[Symbol.for('message')] = `${timestamp} ${level}: ${message} ${strArgs}`;
return info;
}
};
const options = {
file: {
level: 'debug',
filename: './logs/combined.log',
handleExceptions: true,
timestamp: true,
json: false,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false,
},
console: {
level: 'debug',
handleExceptions: true,
timestamp: true,
json: false,
colorize: true,
},
};
const logger = winston.createLogger({
levels: winston.config.npm.levels,
format: winston.format.combine(
winston.format.timestamp(),
logLikeFormat
),
transports: [
new winston.transports.Console(options.console),
new winston.transports.File(options.file)
],
exitOnError: true
})
export default logger;