简体   繁体   中英

nodeJS Winston module example not logging to console

Im trying to test out some winston logging, going by the example posted Here i cannot get this one to work.

I've copy/pasted it onto my js file and pressed F5 in vscode to test the script.

Nothing gets logged.

For a learner its doubly difficult when examples like this dont work as you end up going in circles trying to fix your own environment.

Can someone tell me if this should work?

 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' } 

My nodeJS debug console just quits and displays Debugger attached. Waiting for the debugger to disconnect...

The issue is with the debugger configuration. In VSCode you need to add "outputCapture": "std" to your launch.json file when configuring the debugger.

This option lets debugger capture the data sent to the std output from your code.

Example configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/winston.js",
      "outputCapture": "std", // <-- ADD THIS LINE
    }
  ]
}

EDIT: Forgot to mention that you can run the code you wrote in node directly and it will log the message correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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