Fixing winston duplicate loggers issue

This commit is contained in:
emad-salah 2019-12-01 14:04:10 +01:00
parent 3ee39e63c5
commit 471e7e669e

View file

@ -3,7 +3,10 @@
const winston = require("winston");
require("winston-daily-rotate-file");
module.exports = function(logFileName, logLevel) {
const winstonAttached = new Map();
module.exports = (logFileName, logLevel) => {
if (!winstonAttached.has(logFileName)) {
winston.cli();
winston.level = logLevel;
@ -18,5 +21,10 @@ module.exports = function(logFileName, logLevel) {
level: logLevel
});
winstonAttached.set(logFileName, winston)
return winston;
}
return winstonAttached.get(logFileName);
};