diff --git a/src/common/logger.ts b/src/common/logger.ts index 724cd7b5..d41bbe65 100644 --- a/src/common/logger.ts +++ b/src/common/logger.ts @@ -251,10 +251,12 @@ class Logger { const deleteTimeStamp = new Date().getTime() - (5 * 24 * 60 * 60 * 1000); files.forEach((file) => { const filePath = path.join(this.logPath, file); - const stat = fs.statSync(filePath); - const fileTimestamp = new Date(util.inspect(stat.mtime)).getTime(); - if ((fileTimestamp < deleteTimeStamp) && fs.existsSync(filePath)) { - fs.unlinkSync(filePath); + if (fs.existsSync(filePath)) { + const stat = fs.statSync(filePath); + const fileTimestamp = new Date(util.inspect(stat.mtime)).getTime(); + if ((fileTimestamp < deleteTimeStamp)) { + fs.unlinkSync(filePath); + } } }); }