Skip to content

Commit

Permalink
When rotating based on threshold, rotate to a file with the timestamp…
Browse files Browse the repository at this point in the history
… of the log that caused the threshold instead of to the current time.
  • Loading branch information
Jim Tupper committed Feb 28, 2016
1 parent 35c450b commit ae20de8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/rotatingfilestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ function RotatingFileStream(options) {

var writeBuffer = new Buffer(str, 'utf8');

base.emit('logwrite', { logSize: writeBuffer.byteLength });
var emitinfo = {
logSize: writeBuffer.byteLength,
logstr: str
};

base.emit('logwrite', emitinfo);

if (stream) {
try {
Expand Down
5 changes: 4 additions & 1 deletion lib/thresholdtrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ function ThresholdTrigger(options) {

function logWrite(data) {
if ((bytesWritten > 0) && (bytesWritten + data.logSize > threshold)) {
base.emit('rotate');

var log = JSON.parse(data.logstr);

base.emit('rotate', {date: log.time});
} else {
bytesWritten += data.logSize;
}
Expand Down

0 comments on commit ae20de8

Please sign in to comment.