Domanda

I am using something like this:

var winston = require('winston'), logger = new (winston.Logger)({
  transports: [
    new (winston.transports.Console) (),
    new (winston.transports.File) ({filename: 'test.log'})
  ]
});

logger.log('Hello world');

I cannot find the log file test.log anywhere on my system and no exception or info in the console either.

È stato utile?

Soluzione

Nevermind, I found the answer. If you do not specify directory, it is in the same directory as the code.

Altri suggerimenti

Paste the following snippet in your winston.helper.js

// create directory for logs first
if (!fs.existsSync("logs")) {
    fs.mkdirSync("logs");
}

OR

You can write a command in your package.json script For e.g.

"dev": "mkdir logs | ..."

set the route of the file name like this '${__dirname}/filename' if this not working change the colon into back quote

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top