Merge pull request #2 from shocknet/bug/winston_logger
Fixes an issue where Winston attaches duplicate loggers
This commit is contained in:
commit
9c2df34f0e
1 changed files with 21 additions and 13 deletions
|
|
@ -3,20 +3,28 @@
|
|||
const winston = require("winston");
|
||||
require("winston-daily-rotate-file");
|
||||
|
||||
module.exports = function(logFileName, logLevel) {
|
||||
winston.cli();
|
||||
const winstonAttached = new Map();
|
||||
|
||||
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, {
|
||||
filename: logFileName,
|
||||
datePattern: "yyyy-MM-dd.",
|
||||
prepend: true,
|
||||
json: false,
|
||||
maxSize: 1000000,
|
||||
maxFiles: 7,
|
||||
level: logLevel
|
||||
});
|
||||
winstonAttached.set(logFileName, winston)
|
||||
|
||||
return winston;
|
||||
}
|
||||
|
||||
return winston;
|
||||
return winstonAttached.get(logFileName);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue