Skip to content

Commit b2098fd

Browse files
authored
Add option forceConsole (#2276)
Add new option to the Console transport: forceConsole (Boolean): when true, force transport to use console log/warn/error instead of write. With this option, VSCode terminal will work without setting the "outputCapture" to "std".
1 parent 1719275 commit b2098fd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/winston/transports/console.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = class Console extends TransportStream {
3131
this.stderrLevels = this._stringArrayToSet(options.stderrLevels);
3232
this.consoleWarnLevels = this._stringArrayToSet(options.consoleWarnLevels);
3333
this.eol = (typeof options.eol === 'string') ? options.eol : os.EOL;
34+
this.forceConsole = options.forceConsole || false;
3435

3536
this.setMaxListeners(30);
3637
}
@@ -46,7 +47,7 @@ module.exports = class Console extends TransportStream {
4647

4748
// Remark: what if there is no raw...?
4849
if (this.stderrLevels[info[LEVEL]]) {
49-
if (console._stderr) {
50+
if (console._stderr && !this.forceConsole) {
5051
// Node.js maps `process.stderr` to `console._stderr`.
5152
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
5253
} else {
@@ -59,7 +60,7 @@ module.exports = class Console extends TransportStream {
5960
}
6061
return;
6162
} else if (this.consoleWarnLevels[info[LEVEL]]) {
62-
if (console._stderr) {
63+
if (console._stderr && !this.forceConsole) {
6364
// Node.js maps `process.stderr` to `console._stderr`.
6465
// in Node.js console.warn is an alias for console.error
6566
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
@@ -74,7 +75,7 @@ module.exports = class Console extends TransportStream {
7475
return;
7576
}
7677

77-
if (console._stdout) {
78+
if (console._stdout && !this.forceConsole) {
7879
// Node.js maps `process.stdout` to `console._stdout`.
7980
console._stdout.write(`${info[MESSAGE]}${this.eol}`);
8081
} else {

0 commit comments

Comments
 (0)