Search code examples
node.jsloggingwinston

Winston log to file not working


I use Winston for logging:

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

and I write to this log:

logger.log("File: " + path + " was found");

For some reason, the file /var/log/logF.log isn't updated, and also the standard output isn't shown the log.

How do I use it so the log will be written in '/var/log/logF.log'?


Solution

  • You haven't specified a log "level", and "log" is unfortunately not a default level. Try:

    logger.log("info", "File: was found");
    // or
    logger.info("File: was found");