56

I'm using VSCode debugger and winston logger for NodeJS, but can't see output from application unless I specify external terminal like this:

"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}/server.js",
        "console": "externalTerminal"
    }
]

Is there way to see that output in output window, like when i start code using CodeRunner plugin?

Cody G
  • 8,368
  • 2
  • 35
  • 50
Josip
  • 1,061
  • 1
  • 9
  • 10
  • What node version are you using – Cody G Dec 29 '17 at 19:11
  • At the moment it's 9.0.0. But it was same with older. I wouldn't go in that direction, this should be VSCode related issue/feature – Josip Dec 29 '17 at 19:13
  • 9.0 should be using the inspector protocol, I believe. . . only reason I asked, (but debugging wouldn't work at all if that wasn't set correctly) – Cody G Dec 29 '17 at 19:16
  • 1
    Wait, when you say output you're talking about console.log statements right? – Cody G Dec 29 '17 at 19:16
  • windows/linux might also be important – Cody G Dec 29 '17 at 19:19
  • yes, I mean on console.log(). I'm on macOs – Josip Dec 29 '17 at 19:20
  • Does `integratedTerminal` work ? it should output to the terminal tab – Cody G Dec 29 '17 at 19:22
  • Additionally, you're not running any sort of program that clusters your app, are you? Have you tried running the bare minimum of a program ? I.e., server.js just `console.log('test')` – Cody G Dec 29 '17 at 19:23
  • When I'm using integrated terminal i get this: node --inspect-brk=27768 server.js node: bad option: --inspect-brk=27768 – Josip Dec 29 '17 at 19:26
  • My console log works perfectly in external terminal, but i would like to have it in one place. – Josip Dec 29 '17 at 19:27
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/162185/discussion-between-cody-g-and-josip). – Cody G Dec 29 '17 at 19:27

1 Answers1

159

When using a logger that outputs to

process.stdout.write

you can use

"outputCapture": "std" in the launch config to also capture that.

Cody G
  • 8,368
  • 2
  • 35
  • 50
  • Seems this is an old and accepted answer. As I write this comment in 2022 just this solution didn't work with VSCode version 1.62.2 and winston version 3.8.1. I had to make sure I set the log level to 'debug' in the Console transport to get it working. Something like this: `transports: [ new winston.transports.Console({ level: 'debug' })]` – sribasu Sep 16 '22 at 12:38
  • Level debug would just ensure something like log.debug gets output. If you did a higher level you'd have to use log.info, etc. – Cody G Sep 17 '22 at 14:04
  • what I mean is, just the VS Code Launch config didn't work standalonely. You have to also set the log level to 'debug', in order to see even log.info or log.error logs in Debug Console of VSCode. This is weird but somehow there must be some correlation. It doesn't print even errors or infos if the log level is not set to debug, while you're running the application in debug mode on VS Code – sribasu Sep 25 '22 at 06:00