Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 943
pixel Avatar asked Aug 14 '17 04:08

pixel


People also ask

How do I view logs in Visual Studio?

To examine the activity logRun Visual Studio with the /Log command line switch to write ActivityLog. xml to disk during your session. After closing Visual Studio, find the activity log in the subfolder for Visual Studio data: %AppData%\Microsoft\VisualStudio\<version>\ActivityLog.

Where is the console log output?

Steps to Open the Console Log in Google Chrome By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements". Now you can see the Console and any output that has been written to the Console log.


2 Answers

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.

like image 89
Than Avatar answered Sep 20 '22 16:09

Than


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.

like image 24
OfirD Avatar answered Sep 21 '22 16:09

OfirD