diff --git a/src/logging.cpp b/src/logging.cpp index e4057d9e..f7db38c4 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -4,6 +4,7 @@ */ // standard includes #include +#include #include #include @@ -106,15 +107,26 @@ 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); sink = boost::make_shared(); -#ifndef SUNSHINE_TESTS + #ifndef SUNSHINE_TESTS boost::shared_ptr stream { &std::cout, boost::null_deleter() }; sink->locked_backend()->add_stream(stream); -#endif + #endif sink->locked_backend()->add_stream(boost::make_shared(log_file)); sink->set_filter(severity >= min_log_level); sink->set_formatter(&formatter); @@ -127,6 +139,7 @@ namespace logging { return std::make_unique(); } + void setup_av_logging(int min_log_level) { if (min_log_level >= 1) {