Winston: How to rewrite log file on each program run?

Created on 15 Apr 2018  路  2Comments  路  Source: winstonjs/winston

winston.add(winston.transports.File, { filename: 'log.txt' });

How to specify a rewrite file option, not append?

Most helpful comment

The File transports accepts flags in an options param. For [email protected]:

winston.add(new winston.transports.File, {
  filename: 'your-file.log',
  options: { flags: 'w' }
});

See fs.open docs for what flags are available in Node.js.

All 2 comments

Easiest is to remove the log file before you initiate your logger on each run. You can do this with the fs.unlink or fs.unlinkSync methods.

The File transports accepts flags in an options param. For [email protected]:

winston.add(new winston.transports.File, {
  filename: 'your-file.log',
  options: { flags: 'w' }
});

See fs.open docs for what flags are available in Node.js.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Buzut picture Buzut  路  3Comments

JaehyunLee-B2LiNK picture JaehyunLee-B2LiNK  路  3Comments

KingRial picture KingRial  路  3Comments

Tonacatecuhtli picture Tonacatecuhtli  路  4Comments

jlank picture jlank  路  4Comments