pix*_*xel 8 console logging visual-studio-code
例如,在此方法中,我使用console.log()登录到控制台以进行调试
_onSearchTextChanged = (event) => {
console.log('_onSearchTextChanged');
...
};
Run Code Online (Sandbox Code Playgroud)
但Visual Studio Code在控制台中不显示任何内容
小智 10
如果您在 Visual Studio 代码中使用调试模式,则可以添加选项:
{
"outputCapture": "std"
}
Run Code Online (Sandbox Code Playgroud)
这会将您的日志重定向到调试控制台中。
在内部launch.json(使用 打开它F1)下,使用或configurations添加outputCapture属性(如果尚不存在),如下所示:stdconsole
{
...
"configurations": [
{
...
"outputCapture": "std", // or "console"
}
]
}
Run Code Online (Sandbox Code Playgroud)
至于"std",这是文档所说的:
outputCapture- 如果设置为 std,则进程 stdout/stderr 的输出将显示在调试控制台中,而不是通过调试端口监听输出。这对于直接写入 stdout/stderr 流而不是使用console.*API 的程序或日志库非常有用。
另请注意,使用std将显示完整错误(对于 VSCode 1.49.0)。例如,创建一个包含错误的js文件:
console.log(a) // error: a is undefined
Run Code Online (Sandbox Code Playgroud)
使用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
Run Code Online (Sandbox Code Playgroud)
使用console:
Uncaught ReferenceError: a is not defined
Run Code Online (Sandbox Code Playgroud)
所以在我看来,std更好一些。
小智 -2
如果您在浏览器中运行和测试代码,请按“F12”(适用于 google chrome)以查看浏览器中的日志。如果您在调试模式下运行,则在 Visual Studio Code 中将仅显示日志。在菜单栏中,有“调试”选项可在调试模式下运行,或者您可以在此处找到完整的参考
| 归档时间: |
|
| 查看次数: |
2372 次 |
| 最近记录: |