Как я могу динамически изменять уровень журнала в winston, отражающий изменение уровня в нескольких файлах?
У меня есть два js файла, и я включаю журнал в оба файла. Если я изменю уровень регистратора в index.js, это изменение не будет отражено в readfile.js
Вот мой код:
winston_logger.js
var winston = require('winston');
var logger;
module.exports.init = function (logLevel) {
logger = new(winston.Logger)({
transports: [
new(winston.transports.Console)({
level: logLevel
})
],
exitOnError: false
});
}
module.exports.getLogger = function (config) {
if (!module.exports.logger) {
exports.init('info')
}
return logger;
}
module.exports.debugLevel = function(){
logger.transports.console.level = 'debug'
}
index.js
var readFile = require('./readFile')
var winston = require('./winston_logger')
var log = winston.getLogger()
log.info("info message" );
/*Here Im changing the log level as debug*/
winston.debugLevel ();
setTimeout(function(){
readFile(function(){})
}, 5000)
readfile.js
var readFile = require('./readFile')
var winston = require('./winston_logger')
var log = winston.getLogger()
log.info("info message" );
/*Here Im changing the log level as debug*/
winston.debugLevel ();
setTimeout(function(){
readFile(function(){})
}, 5000)
Не ставьте этот вопрос как дублирующийся вопрос. Эти ответы мне не помогли.
winston_logger.js
var winston = require('winston');
winston.configure({
transports: [
new (winston.transports.Console)({ timestamp: true, json : false , colorize: true}),
new (winston.transports.File)({filename: './somefile.log' , json : true, timestamp: true })
]
});
module.exports = winston;
Я могу изменить уровень журнала из любого места. Спасибо
В readfile.js импортируйте winston_logger так же, как вы импортируете его в index.js