Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 240
Or Smith Avatar asked Jan 08 '15 11:01

Or Smith


3 Answers

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");
like image 198
laggingreflex Avatar answered Oct 17 '22 05:10

laggingreflex


After trying and made severals tests with severals advanced logging mechanisms (incl. winston, bunyan, log4js), it appears that loggers are not able to write into file if you do a clean exit process.exit(0). Removing clean exit solve the problem for me.

like image 4
Fabien Avatar answered Oct 17 '22 05:10

Fabien


I had this issue this evening. However, I realized the file location wasn't being resolved. I'm not sure if this will solve your issue.

filename: path.resolve(__dirname, "add_your_relative_path/error.log")
like image 1
Karl-Johan Bailey Avatar answered Oct 17 '22 07:10

Karl-Johan Bailey