pixel
pixel

Reputation: 10537

Visual Studio Code not showing console logs

For example, in this method, I use console.log() to log to console for debugging purposes

_onSearchTextChanged = (event) => {
    console.log('_onSearchTextChanged');
    ...
};

But Visual Studio Code does not show anyting in console

enter image description here

Upvotes: 31

Views: 51065

Answers (5)

Suresh Kumar A
Suresh Kumar A

Reputation: 71

In Latest version of VSCode(1.83.1) the property name is changed. You have to instead use the below property

"console": "internalConsole"

Sample launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}/src/app/pages/auth/auth.component.ts",
      "outFiles": [
        "${workspaceFolder}/**/*.js"
      ],
      "console": "internalConsole"
    }
  ]
}

Upvotes: 3

vish213
vish213

Reputation: 786

In my case, I searched a text in the search bar long ago and searched text never got removed from the search bar. The search bar is so easy to miss, although it shown the text 0/173 signifying 0 lines matched out of 173 printed, but I couldn't figure out why DEBUG CONSOLE was completely empty. Hope this helps someone!

Upvotes: 2

Than
Than

Reputation: 446

If you are using the debug mode in visual studio code, you can add the option:

{
 "outputCapture": "std"
}

That will redirect your logs inside the debug console.

EDIT : as mentioned by Luigi04 in the comment section, this setting need to be put inside the launch.json

Upvotes: 23

OfirD
OfirD

Reputation: 10461

Inside launch.json (open it using F1), under configurations, add the outputCapture property (if not already exists) with either std or console, as follows :

{
  ...
  "configurations": [
    {
      ...
      "outputCapture": "std", // or "console" 
    }
  ]
}

as for "std", this is what the documentation has to say:

outputCapture - if set to std, output from the process stdout/stderr will be shown in the Debug Console, instead of listening to output over the debug port. This is useful for programs or log libraries that write directly to the stdout/stderr streams instead of using console.* APIs.

Also note that using std will show you full errors (as for VSCode 1.49.0). For example, create a js file containing an error:

console.log(a) // error: a is undefined

Using std:

c: \Users\path\to\file.js: 1
console.log(a) // error: a is undefined
    ^

ReferenceError: a is not defined
at Object.<anonymous>(c: \Users\path\to\file.js: 1: 13)
at Module._compile(internal / modules / cjs / loader.js: 1158: 30)
at Object.Module._extensions..js(internal / modules / cjs / loader.js: 1178: 10)
at Module.load(internal / modules / cjs / loader.js: 1002: 32)
at Function.Module._load(internal / modules / cjs / loader.js: 901: 14)
at Function.executeUserEntryPoint[as runMain](internal / modules / run_main.js: 74: 12)
at internal / main / run_main_module.js: 18: 47

Using console:

Uncaught ReferenceError: a is not defined

so in my opinion, std is somewhat better.

Upvotes: 7

Vatsal Mehta
Vatsal Mehta

Reputation: 115

If you are running & testing your code in the browser the press 'F12' (for google chrome) to see the logs in the browser. If you are running in the debug mode, In Visual Studio Code then only logs will be displayed.In the menu bar there is Debug option to run in debug mode or u can find complete reference here

Upvotes: -2

Related Questions