Skip to content

Commit

Permalink
Added check for maximum number of log files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio Scalzo committed Jun 14, 2018
1 parent 9c1392d commit 6576e81
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ module.exports = function() {

// threshold reached: update name/num to create a new file next time
if (fs.statSync(logFilePath).size > threshold) {
logFile.num += 1;
logFile.name = "doremus_log_" + logFile.num.toString().padStart(3, "0") + ".csv";
fs.writeFileSync(path.join(logDir, logFile.name), getHeader());
if (logFile.num === 999) {
console.warn('Exceeded maximum number of log files! Appending to the last one...');
} else {
logFile.num += 1;
logFile.name = "doremus_log_" + logFile.num.toString().padStart(3, "0") + ".csv";
fs.writeFileSync(path.join(logDir, logFile.name), getHeader());
}
}
}
});
Expand Down

0 comments on commit 6576e81

Please sign in to comment.