Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js / winston - Can I append log?

I use winston.log to append log files. Every time I restart my application, the exist log is deleted, and new one is created.

Is there any way to append the logs files? so it will deleted just in rotate rule?

Here is the relevant code:

    var winston = require('winston');
    var loggerNoCache = new(winston.Logger)({
        transports: [
            new(winston.transports.File)({
                filename: '/var/log/logNo.log',
                options: {
                    highWaterMark: 32
                }
            })
        ]
    });
like image 554
MIDE11 Avatar asked Mar 08 '15 09:03

MIDE11


2 Answers

You could pass an appendable WriteableStream via the stream property, perhaps something like:

new(winston.transports.File)({
  stream: fs.createWriteStream('/var/log/logNo.log', {flags: 'a'}),
  options: {
    ...
like image 118
Lovell Fuller Avatar answered Oct 13 '22 09:10

Lovell Fuller


Most recent solution for streams in winston :

new winston.transports.Stream({
  stream: fs.createWriteStream('/var/log/logNo.log', {flags: 'a'}),
  level: fileLoggingLevel
}));
like image 23
M.Liscio Avatar answered Oct 13 '22 09:10

M.Liscio