Fixing winston duplicate loggers issue
This commit is contained in:
parent
3ee39e63c5
commit
471e7e669e
1 changed files with 21 additions and 13 deletions
|
|
@ -3,20 +3,28 @@
|
||||||
const winston = require("winston");
|
const winston = require("winston");
|
||||||
require("winston-daily-rotate-file");
|
require("winston-daily-rotate-file");
|
||||||
|
|
||||||
module.exports = function(logFileName, logLevel) {
|
const winstonAttached = new Map();
|
||||||
winston.cli();
|
|
||||||
|
|
||||||
winston.level = logLevel;
|
module.exports = (logFileName, logLevel) => {
|
||||||
|
if (!winstonAttached.has(logFileName)) {
|
||||||
|
winston.cli();
|
||||||
|
|
||||||
|
winston.level = logLevel;
|
||||||
|
|
||||||
|
winston.add(winston.transports.DailyRotateFile, {
|
||||||
|
filename: logFileName,
|
||||||
|
datePattern: "yyyy-MM-dd.",
|
||||||
|
prepend: true,
|
||||||
|
json: false,
|
||||||
|
maxSize: 1000000,
|
||||||
|
maxFiles: 7,
|
||||||
|
level: logLevel
|
||||||
|
});
|
||||||
|
|
||||||
winston.add(winston.transports.DailyRotateFile, {
|
winstonAttached.set(logFileName, winston)
|
||||||
filename: logFileName,
|
|
||||||
datePattern: "yyyy-MM-dd.",
|
return winston;
|
||||||
prepend: true,
|
}
|
||||||
json: false,
|
|
||||||
maxSize: 1000000,
|
|
||||||
maxFiles: 7,
|
|
||||||
level: logLevel
|
|
||||||
});
|
|
||||||
|
|
||||||
return winston;
|
return winstonAttached.get(logFileName);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue