Skip to content

Commit

Permalink
Fix unlink
Browse files Browse the repository at this point in the history
  • Loading branch information
C-D-Lewis committed Oct 23, 2024
1 parent db2d45c commit b8d6cb3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions node-common/src/modules/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ const getLogfileSizeMb = () => {
* Monitor the log size, and erase if it gets too big.
*/
const monitorLogSize = () => {
// Initally clear
fs.unlinkSync(getFilePath());
const filePath = getFilePath();

if (fs.existsSync(filePath)) {
// Initally clear
fs.unlinkSync(getFilePath());
}

setInterval(() => {
const sizeMb = getLogfileSizeMb();
Expand All @@ -187,7 +191,7 @@ const monitorLogSize = () => {
if (sizeMb < MAX_SIZE_MB) return;

// Erase the file and start again
fs.unlinkSync(getFilePath());
fs.unlinkSync(filePath);
info('Log file exceeded max size and was restarted');
}, MONITOR_INTERVAL_MS);
info(`Monitoring logfile size (currently ${getLogfileSizeMb()} MB)`);
Expand Down

0 comments on commit b8d6cb3

Please sign in to comment.