From 2458ba61ab41fac576b8bded3cd3472e05e3c250 Mon Sep 17 00:00:00 2001 From: Neil Enns Date: Tue, 13 Aug 2024 17:19:03 -0700 Subject: [PATCH] Move initialization to constructor (#2503) Fixes #2502 --- lib/winston/transports/console.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/winston/transports/console.js b/lib/winston/transports/console.js index 0679045eb..25ab78469 100644 --- a/lib/winston/transports/console.js +++ b/lib/winston/transports/console.js @@ -18,13 +18,6 @@ const TransportStream = require('winston-transport'); * @extends {TransportStream} */ module.exports = class Console extends TransportStream { - // Keep a reference to the log, warn, and error console methods - // in case they get redirected to this transport after the logger is - // instantiated. This prevents a circular reference issue. - _consoleLog = console.log.bind(console); - _consoleWarn = console.warn.bind(console); - _consoleError = console.error.bind(console); - /** * Constructor function for the Console transport object responsible for * persisting log messages and metadata to a terminal or TTY. @@ -40,6 +33,13 @@ module.exports = class Console extends TransportStream { this.eol = typeof options.eol === 'string' ? options.eol : os.EOL; this.forceConsole = options.forceConsole || false; + // Keep a reference to the log, warn, and error console methods + // in case they get redirected to this transport after the logger is + // instantiated. This prevents a circular reference issue. + this._consoleLog = console.log.bind(console); + this._consoleWarn = console.warn.bind(console); + this._consoleError = console.error.bind(console); + this.setMaxListeners(30); }