From ae20de8134ea107859b091845d09ce6cfe91683c Mon Sep 17 00:00:00 2001 From: Jim Tupper Date: Sun, 28 Feb 2016 21:53:35 +0000 Subject: [PATCH] When rotating based on threshold, rotate to a file with the timestamp of the log that caused the threshold instead of to the current time. --- lib/rotatingfilestream.js | 7 ++++++- lib/thresholdtrigger.js | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/rotatingfilestream.js b/lib/rotatingfilestream.js index 8a3a539..a976a03 100644 --- a/lib/rotatingfilestream.js +++ b/lib/rotatingfilestream.js @@ -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 { diff --git a/lib/thresholdtrigger.js b/lib/thresholdtrigger.js index ba80e28..95b6690 100644 --- a/lib/thresholdtrigger.js +++ b/lib/thresholdtrigger.js @@ -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; }