[feat] just set the deleteLogFolders than appending the new list

This commit is contained in:
silentrald
2025-01-22 08:35:47 +08:00
parent ec0ae76d70
commit 93bcd358cb
+3 -5
View File
@@ -224,15 +224,13 @@ function initLogger(){
// Keep only the past week (7 days) of logs
function deleteOldLogs(): void {
const deleteLogFolders: Dirent[] = [];
let deleteLogFolders: Dirent[] = [];
try {
const filterDate = convertDateToDateString(
new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) // 7 days
);
deleteLogFolders.push.apply([],
readdirSync(app.getPath("logs"), { withFileTypes: true })
.filter(folder => folder.isDirectory() && folder.name <= filterDate)
);
deleteLogFolders = readdirSync(app.getPath("logs"), { withFileTypes: true })
.filter(folder => folder.isDirectory() && folder.name <= filterDate);
} catch (error) {
log.error("Error while deleting old logs:", error);
return;