Skip to content

Commit

Permalink
CleanOldLogFiles respects log_dir (rime#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored and graphemecluster committed Oct 8, 2023
1 parent a596c0a commit 0cecd77
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/rime/lever/deployment_tasks.cc
Expand Up @@ -630,26 +630,21 @@ bool CleanupTrash::Run(Deployer* deployer) {
}

bool CleanOldLogFiles::Run(Deployer* deployer) {
bool success = true;
#ifdef RIME_ENABLE_LOGGING
if (FLAGS_logtostderr) {
return success;
}

char ymd[12] = {0};
time_t now = time(NULL);
strftime(ymd, sizeof(ymd), ".%Y%m%d", localtime(&now));
string today(ymd);
DLOG(INFO) << "today: " << today;

vector<string> dirs;
#ifdef RIME_ENABLE_LOGGING
#ifdef _WIN32
// work-around: google::GetExistingTempDirectories crashes on windows 7
char tmp[MAX_PATH];
if (GetTempPathA(MAX_PATH, tmp))
dirs.push_back(tmp);
#else
google::GetExistingTempDirectories(&dirs);
#endif // _WIN32
#endif // RIME_ENABLE_LOGGING
vector<string> dirs = google::GetLoggingDirectories();
DLOG(INFO) << "scanning " << dirs.size() << " temp directory for log files.";

bool success = true;
int removed = 0;
for (auto i = dirs.cbegin(); i != dirs.cend(); ++i) {
DLOG(INFO) << "temp directory: " << *i;
Expand All @@ -673,6 +668,7 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
if (removed != 0) {
LOG(INFO) << "cleaned " << removed << " log files.";
}
#endif // RIME_ENABLE_LOGGING
return success;
}

Expand Down

0 comments on commit 0cecd77

Please sign in to comment.