winston version?_ 3.2.1node -v outputs:_ v10.4.1while using the Proxy object, the handler.get() will be called multiple times.
e.g.
const winston = require('winston');
const logger = winston.createLogger();
const proxyLogger = new Proxy(logger, {
get(target, prop) {
console.log('handler.get() is called');
return target[prop];
}
});
proxyLogger.info('12312323');
the output result:
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
[winston] Attempt to write logs with no transports {"message":"12312323","level":"info"}
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() is called
handler.get() should be called only once.
if you edit the console.log and print the prop variable you will see its getting called for all the methods inside winston
handler.get() is called info
handler.get() is called _addDefaultMeta
handler.get() is called defaultMeta
handler.get() is called write
handler.get() is called _writableState
handler.get() is called _write
handler.get() is called _transformState
handler.get() is called _readableState
handler.get() is called _read
handler.get() is called _transformState
handler.get() is called _transform
handler.get() is called silent
handler.get() is called levels
handler.get() is called _readableState
[winston] Attempt to write logs with no transports {"message":"12312323","level":"info"}
handler.get() is called push
handler.get() is called format
handler.get() is called format
handler.get() is called _transformState
handler.get() is called _readableState
handler.get() is called _readableState
handler.get() is called _readableState
handler.get() is called _readableState
handler.get() is called emit
handler.get() is called _events
handler.get() is called domain
handler.get() is called _readableState
handler.get() is called read
handler.get() is called _readableState
handler.get() is called _read
handler.get() is called _transformState
Modify your function to be called only for the info method you call
const proxyLogger = new Proxy(logger, {
get: (target, prop) => {
return (...args) => {
console.log('handler.get() is called', prop);
return target[prop](...args);
}
}
});
Most helpful comment
Modify your function to be called only for the info method you call