pla*_*ums 1 javascript node.js winston
我正在尝试测试一些Winston日志记录,并按此处发布的示例进行操作,但我无法运行此示例。
我已经将其复制/粘贴到我的js文件中,然后在vscode中按F5键来测试脚本。
什么都没有记录。
对于一个学习者来说,当像这样的例子无法正常工作时,如果您最终试图修复自己的环境,这将加倍困难。
有人可以告诉我这是否有效吗?
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, prettyPrint } = format;
const logger = createLogger({
format: combine(
label({ label: 'right meow!' }),
timestamp(),
prettyPrint()
),
transports: [new transports.Console()]
})
logger.log({
level: 'info',
message: 'What time is the testing at?'
});
// Outputs:
// { level: 'info',
// message: 'What time is the testing at?',
// label: 'right meow!',
// timestamp: '2017-09-30T03:57:26.875Z' }
Run Code Online (Sandbox Code Playgroud)
我的nodeJS调试控制台只是退出并显示附加的调试器。等待调试器断开连接...
问题出在调试器配置上。在VSCode中"outputCapture": "std"
,配置调试器时需要添加到launch.json文件中。
此选项使调试器可以捕获代码中发送到std输出的数据。
配置示例:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/winston.js",
"outputCapture": "std", // <-- ADD THIS LINE
}
]
}
Run Code Online (Sandbox Code Playgroud)
编辑:忘记提及您可以直接运行在节点中编写的代码,它将正确记录消息。