Skip to content

Commit

Permalink
Move initialization to constructor (#2503)
Browse files Browse the repository at this point in the history
Fixes #2502
  • Loading branch information
neilenns committed Aug 14, 2024
1 parent b270c4e commit 2458ba6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/winston/transports/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

Expand Down

0 comments on commit 2458ba6

Please sign in to comment.