NEW: limit log files within 30 by deleting old files

Change-Id: I1bb5c827c7fb01d97b84a4a1bf3f905bb8e90448
(cherry picked from commit 065ef224357352851cbba2c0dcac131ea9acae82)
This commit is contained in:
tao.jin 2022-09-27 12:38:06 +08:00 committed by Lane.Wei
parent 6f01c4841d
commit 5179b745e1
2 changed files with 26 additions and 0 deletions

View file

@ -1096,6 +1096,31 @@ void GUI_App::post_init()
std::string functional_config_file = Slic3r::resources_dir() + "/config.json";
DeviceManager::load_functional_config(encode_path(functional_config_file.c_str()));
// remove old log files over LOG_FILES_MAX_NUM
std::string log_addr = data_dir();
if (!log_addr.empty()) {
auto log_folder = boost::filesystem::path(log_addr) / "log";
if (boost::filesystem::exists(log_folder)) {
std::vector<std::pair<time_t, std::string>> files_vec;
for (auto& it : boost::filesystem::directory_iterator(log_folder)) {
auto temp_path = it.path();
std::time_t lw_t = boost::filesystem::last_write_time(temp_path) ;
files_vec.push_back({ lw_t, temp_path.filename().string() });
}
std::sort(files_vec.begin(), files_vec.end(), [](
std::pair<time_t, std::string> &a, std::pair<time_t, std::string> &b) {
return a.first > b.first;
});
while (files_vec.size() > LOG_FILES_MAX_NUM) {
auto full_path = log_folder / boost::filesystem::path(files_vec[files_vec.size() - 1].second);
BOOST_LOG_TRIVIAL(info) << "delete log file over " << LOG_FILES_MAX_NUM << ", filename: "<< files_vec[files_vec.size() - 1].second;
boost::filesystem::remove(full_path);
files_vec.pop_back();
}
}
}
BOOST_LOG_TRIVIAL(info) << "finished post_init";
//BBS: remove the single instance currently
/*#ifdef _WIN32

View file

@ -26,6 +26,7 @@
#define BBL_HAS_FIRST_PAGE 1
#define STUDIO_INACTIVE_TIMEOUT 15*60*1000
#define LOG_FILES_MAX_NUM 30
class wxMenuItem;
class wxMenuBar;