Rotate logs

This commit is contained in:
Yukino Song
2025-01-15 22:59:14 +08:00
parent a3c8c937af
commit c4e9ceea1b
+13
View File
@@ -4,6 +4,7 @@
*/
// standard includes
#include <fstream>
#include <filesystem>
#include <iomanip>
#include <iostream>
@@ -106,6 +107,17 @@ namespace logging {
deinit();
}
// Check if the log file exists and handle backup
std::string backup_log_file = log_file + ".backup";
if (std::filesystem::exists(log_file)) {
// If the backup file exists, remove it
if (std::filesystem::exists(backup_log_file)) {
std::filesystem::remove(backup_log_file);
}
// Rename the current log file to the backup name
std::filesystem::rename(log_file, backup_log_file);
}
setup_av_logging(min_log_level);
setup_libdisplaydevice_logging(min_log_level);
@@ -127,6 +139,7 @@ namespace logging {
return std::make_unique<deinit_t>();
}
void
setup_av_logging(int min_log_level) {
if (min_log_level >= 1) {