Skip to content

Commit

Permalink
Add option forceConsole (#2276)
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
szolnokit committed Aug 6, 2024
1 parent 1719275 commit b2098fd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/winston/transports/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = class Console extends TransportStream {
this.stderrLevels = this._stringArrayToSet(options.stderrLevels);
this.consoleWarnLevels = this._stringArrayToSet(options.consoleWarnLevels);
this.eol = (typeof options.eol === 'string') ? options.eol : os.EOL;
this.forceConsole = options.forceConsole || false;

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

// Remark: what if there is no raw...?
if (this.stderrLevels[info[LEVEL]]) {
if (console._stderr) {
if (console._stderr && !this.forceConsole) {
// Node.js maps `process.stderr` to `console._stderr`.
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
} else {
Expand All @@ -59,7 +60,7 @@ module.exports = class Console extends TransportStream {
}
return;
} else if (this.consoleWarnLevels[info[LEVEL]]) {
if (console._stderr) {
if (console._stderr && !this.forceConsole) {
// Node.js maps `process.stderr` to `console._stderr`.
// in Node.js console.warn is an alias for console.error
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
Expand All @@ -74,7 +75,7 @@ module.exports = class Console extends TransportStream {
return;
}

if (console._stdout) {
if (console._stdout && !this.forceConsole) {
// Node.js maps `process.stdout` to `console._stdout`.
console._stdout.write(`${info[MESSAGE]}${this.eol}`);
} else {
Expand Down

0 comments on commit b2098fd

Please sign in to comment.