Skip to content

Commit 2458ba6

Browse files
authored
Move initialization to constructor (#2503)
Fixes #2502
1 parent b270c4e commit 2458ba6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/winston/transports/console.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ const TransportStream = require('winston-transport');
1818
* @extends {TransportStream}
1919
*/
2020
module.exports = class Console extends TransportStream {
21-
// Keep a reference to the log, warn, and error console methods
22-
// in case they get redirected to this transport after the logger is
23-
// instantiated. This prevents a circular reference issue.
24-
_consoleLog = console.log.bind(console);
25-
_consoleWarn = console.warn.bind(console);
26-
_consoleError = console.error.bind(console);
27-
2821
/**
2922
* Constructor function for the Console transport object responsible for
3023
* persisting log messages and metadata to a terminal or TTY.
@@ -40,6 +33,13 @@ module.exports = class Console extends TransportStream {
4033
this.eol = typeof options.eol === 'string' ? options.eol : os.EOL;
4134
this.forceConsole = options.forceConsole || false;
4235

36+
// Keep a reference to the log, warn, and error console methods
37+
// in case they get redirected to this transport after the logger is
38+
// instantiated. This prevents a circular reference issue.
39+
this._consoleLog = console.log.bind(console);
40+
this._consoleWarn = console.warn.bind(console);
41+
this._consoleError = console.error.bind(console);
42+
4343
this.setMaxListeners(30);
4444
}
4545

0 commit comments

Comments
 (0)