logger.js
1.94 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
"use strict";
const PID = process.pid;
const winston = require('winston');
require('winston-daily-rotate-file');
require('winston-circular-buffer');
const logDirectory = process.cwd() + '/logs';
const filenamePrefix = (process.env.KOMODO_LOG_FILENAME || "log.");
// const processTitle = process.title;
const logger = winston.createLogger({
// levels: winston.config.syslog.levels,
transports: [
/*
new (winston.transports.Console)({
timestamp: process.stdout.isTTY ? moment() : null,
level: 'verbose',
}),
*/
new (winston.transports.Console) ({
format: winston.format.combine(
winston.format.metadata(),
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
winston.format.label({ label: `${process.title}[${PID}]`, message: false }),
winston.format.printf((info) => `${process.stdout.isTTY ? info.timestamp : ''} ${info.label}: ${info.level}: ${info.message} ${info.metadata && Object.keys(info.metadata).length ? JSON.stringify(info.metadata) : ''}`.trim()),
)
}),
new (winston.transports.DailyRotateFile) ({
filename: `${filenamePrefix}%DATE%`,
dirname: logDirectory,
datePattern: 'YYYY-MM-DD',
format: winston.format.combine(
winston.format.metadata(),
winston.format.label({ label: `${process.title}[${PID}]`, message: false }),
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
winston.format.json(),
)
}),
/*
new (winston.transports.CircularBuffer) ({
name: 'logs',
level: "verbose",
json: true,
size: 500
}),
*/
]
});
logger.info('Logger initialized');
require('./logger-circular-buffer-web');
module.exports = logger;