Skip to content

Commit

Permalink
When restarting, if using filesize it will continue on the last file …
Browse files Browse the repository at this point in the history
…if below the threshold. Based on PR#27 by Matt Berther
  • Loading branch information
rcastells committed Feb 17, 2018
1 parent 577d2cc commit a968569
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions FileStreamRotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit a968569

Please sign in to comment.