From a968569ee44e21b9ce8ae48e383b8339f41133ca Mon Sep 17 00:00:00 2001 From: rcastells Date: Sat, 17 Feb 2018 17:32:05 +0000 Subject: [PATCH] When restarting, if using filesize it will continue on the last file if below the threshold. Based on PR#27 by Matt Berther --- FileStreamRotator.js | 10 ++++++++++ package.json | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/FileStreamRotator.js b/FileStreamRotator.js index 655d815..9530c5f 100644 --- a/FileStreamRotator.js +++ b/FileStreamRotator.js @@ -372,12 +372,22 @@ FileStreamRotator.getStream = function (options) { } if(fileSize){ + var lastLogFile = null; var t_log = logfile; var f = null; while(f = fs.existsSync(t_log)){ + lastLogFile = t_log; fileCount++; t_log = logfile + "." + fileCount; } + if(lastLogFile){ + var lastLogFileStats = fs.statSync(lastLogFile); + if(lastLogFileStats.size < fileSize){ + t_log = lastLogFile; + fileCount--; + curSize = lastLogFileStats.size; + } + } logfile = t_log; } diff --git a/package.json b/package.json index 66c59f4..264b710 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "file-stream-rotator", - "version": "0.2.0", - "description": "Automated stream rotation", + "version": "0.2.1", + "description": "Automated stream rotation useful for log files", "main": "FileStreamRotator.js", "scripts": { "test": "node test.js"