log4js-node / streamroller

node.js file streams that roll over when they reach a maximum size, or a date/time.
MIT License
38 stars 19 forks source link

Allow zero backups #59

Closed gabrielbrieva closed 2 years ago

gabrielbrieva commented 4 years ago

It is possible to allow zero backups files?

lamweili commented 2 years ago

I tried the following and it didn't work.

var rollers = require('streamroller');
var stream = new rollers.RollingFileStream('myfile', 3, 0);
stream.write("abc");
stream.write("def");
stream.write("ghi");
stream.end();

Output:

myfile   - ghi
myfile.1 - def
lamweili commented 2 years ago

I tried the following and it now works.

Important It is also to note the file does not roll within itself (truncate its older entry for newer entry). It truncates all and appends only the new entry.

var rollers = require('streamroller');
var stream = new rollers.RollingFileStream('myfile', 6, 0);
stream.write("abc"); // add as first row
stream.write("def"); // add as second row
stream.write("ghi"); // truncate all and add as first row
stream.end();

Output:

myfile   - ghi
lamweili commented 2 years ago

For details, refer to https://github.com/log4js-node/streamroller/pull/74#issue-1100170368