question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Console logger - use console.log instead of process.stdout.write?

See original GitHub issue

I noticed that you write to process.stdout.write instead of console.log here: https://github.com/winstonjs/winston/blob/master/lib/winston/transports/console.js#L121, and I see in issues like this - https://github.com/Microsoft/vscode/issues/19750 - that process.stdout.write isn’t sent over the v8-inspector debug protocol socket. So if users are using vscode or chrome devtools to debug Node, they won’t see those messages. If you use console.log instead, they will see them. Is there anything blocking you from using console.log instead?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:26
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
sgronblocommented, Feb 5, 2018

This seems to affect Lambdas as well…

What’s wrong with just making this configurable?

3reactions
luatndcommented, Jan 25, 2020

After failed with node-bind-std-to-console. I end up with this solution:

logger.add(supportNodeInspect(new winston.transports.Console({
        format: winston.format.simple()
      })));

/**
 * Override the winston console transport to support node --inspect, nodemon --inspect
 * Because winston will use stdout, stderror with higher priority than console.log
 */
function supportNodeInspect(winstonTransportsConsoleInstance) {
  const originLog = winstonTransportsConsoleInstance.log.bind(winstonTransportsConsoleInstance);

  // Override log fn to support log to node --inspect
  winstonTransportsConsoleInstance.log = (info, callback) => {
    originLog(info, callback);

    const {
            level,
            message,
            [LEVEL]: l,
            [MESSAGE]: m,
            [SPLAT]: s,
            ...meta
          } = info;
    console[level in console ? level : 'log'](message, meta);
  }

  return winstonTransportsConsoleInstance;
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Difference between "process.stdout.write" and "console.log" in ...
The Simple Difference is: console.log() methods automatically append new line character. It means if we are looping ...
Read more >
Difference between process.stdout.write and console.log in ...
Both process.stdout.write and console.log in NodeJS have basic functionality to display messages on the console. Basically console.log ...
Read more >
Using process.stdout in place of console.log
In some cases I might want to use process.stdout in place of console.log when working out a nodejs script. The console.log method works...
Read more >
Difference between console.log and process.stdout.write in ...
Both the methods – console.log and process.stdout.write have a basic definition to write or print the statements on the console.
Read more >
Digging Into Node.js Console Log & Process stdout
Then, logging to the console is compared against writing to standard output using … ... The "Console Log & Process stdout" Lesson is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found