From 8cf6a8bc98ec232934adaafe3a5b173a08ae3140 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 29 Aug 2023 18:11:27 -0500 Subject: [PATCH] Clean up old log files if more than 10 exist --- app/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/main.cpp b/app/main.cpp index bf3fc0f0..77dd2b09 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -326,6 +326,15 @@ int main(int argc, char *argv[]) SetUnhandledExceptionFilter(UnhandledExceptionHandler); #endif +#ifdef LOG_TO_FILE + // Prune the oldest existing logs if there are more than 10 + QStringList existingLogNames = tempDir.entryList(QStringList("Moonlight-*.log"), QDir::NoFilter, QDir::SortFlag::Time); + for (int i = 10; i < existingLogNames.size(); i++) { + qInfo() << "Removing old log file:" << existingLogNames.at(i); + QFile(tempDir.filePath(existingLogNames.at(i))).remove(); + } +#endif + #if defined(Q_OS_WIN32) // Force AntiHooking.dll to be statically imported and loaded // by ntdll on Win32 platforms by calling a dummy function.