Visual Studio Code 不显示控制台日志

问题描述 投票:0回答:5

例如,在这个方法中,我使用 console.log() 记录到控制台以进行调试

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

但是 Visual Studio Code 在控制台中没有显示任何内容

logging console visual-studio-code
5个回答
23
投票

如果您在 Visual Studio Code 中使用调试模式,可以添加选项:

{
 "outputCapture": "std"
}

这将在调试控制台内重定向您的日志。

编辑:正如Luigi04在评论部分提到的,此设置需要放在launch.json中


6
投票

launch.json
内部(使用 F1 打开它),在
configurations
下,使用
outputCapture
std
添加
console
属性(如果尚不存在),如下所示:

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

至于

"std"
,这是文档所说的:

outputCapture
- 如果设置为 std,则从进程 stdout/stderr 输出 将显示在调试控制台中,而不是监听输出 通过调试端口。这对于以下程序或日志库很有用 直接写入 stdout/stderr 流,而不是使用
console.*
API。

另请注意,使用

std
将显示完整错误(对于 VSCode 1.49.0)。例如,创建一个包含错误的js文件:

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

使用

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

使用

console

Uncaught ReferenceError: a is not defined

所以在我看来,

std
更好一些。


0
投票

就我而言,我很久以前在搜索栏中搜索过文本,并且搜索到的文本从未从搜索栏中删除。搜索栏很容易被错过,尽管它显示文本 0/173 表示 0 行与打印的 173 行相匹配,但我不明白为什么 DEBUG CONSOLE 完全是空的。希望这对某人有帮助!


0
投票

在最新版本的 VSCode(1.83.1) 中,属性名称已更改。您必须改用以下属性

“控制台”:“内部控制台”


-1
投票

如果您在浏览器中运行和测试代码,请按“F12”(对于谷歌浏览器)以查看浏览器中的日志。 如果您在调试模式下运行,则在 Visual Studio Code 中将仅显示日志。在菜单栏中,有“调试”选项可在调试模式下运行,或者您可以在此处

找到完整的参考
© www.soinside.com 2019 - 2024. All rights reserved.