繁体   English   中英

nodeJS Winston模块示例未记录到控制台

[英]nodeJS Winston module example not logging to console

我正在尝试测试一些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' } 

我的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
    }
  ]
}

编辑:忘记提及您可以直接运行在节点中编写的代码,它将正确记录消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM