Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogCleaner: make overdue_days_ unsigned int #760

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ typedef void (*logging_fail_func_t)();
GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(logging_fail_func_t fail_func);

// Enable/Disable old log cleaner.
GOOGLE_GLOG_DLL_DECL void EnableLogCleaner(int overdue_days);
GOOGLE_GLOG_DLL_DECL void EnableLogCleaner(unsigned int overdue_days);
GOOGLE_GLOG_DLL_DECL void DisableLogCleaner();
GOOGLE_GLOG_DLL_DECL void SetApplicationFingerprint(const std::string& fingerprint);

Expand Down
25 changes: 13 additions & 12 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,10 @@ class LogCleaner {
public:
LogCleaner();

void Enable(int overdue_days);
// Setting overdue_days to 0 days will delete all logs.
void Enable(unsigned int overdue_days);
void Disable();

void Run(bool base_filename_selected,
const string& base_filename,
const string& filename_extension) const;
Expand All @@ -486,18 +488,19 @@ class LogCleaner {

private:
vector<string> GetOverdueLogNames(string log_directory,
int days,
unsigned int days,
const string& base_filename,
const string& filename_extension) const;

bool IsLogFromCurrentProject(const string& filepath,
const string& base_filename,
const string& filename_extension) const;

bool IsLogLastModifiedOver(const string& filepath, int days) const;
bool IsLogLastModifiedOver(const string& filepath,
unsigned int days) const;

bool enabled_;
int overdue_days_;
unsigned int overdue_days_;
};

LogCleaner log_cleaner;
Expand Down Expand Up @@ -1299,10 +1302,7 @@ void LogFileObject::Write(bool force_flush,

LogCleaner::LogCleaner() : enabled_(false), overdue_days_(7) {}

void LogCleaner::Enable(int overdue_days) {
// Setting overdue_days to 0 days will delete all logs.
assert(overdue_days >= 0);

void LogCleaner::Enable(unsigned int overdue_days) {
enabled_ = true;
overdue_days_ = overdue_days;
}
Expand All @@ -1314,7 +1314,7 @@ void LogCleaner::Disable() {
void LogCleaner::Run(bool base_filename_selected,
const string& base_filename,
const string& filename_extension) const {
assert(enabled_ && overdue_days_ >= 0);
assert(enabled_);
assert(!base_filename_selected || !base_filename.empty());

vector<string> dirs;
Expand Down Expand Up @@ -1344,7 +1344,7 @@ void LogCleaner::Run(bool base_filename_selected,
}

vector<string> LogCleaner::GetOverdueLogNames(string log_directory,
int days,
unsigned int days,
const string& base_filename,
const string& filename_extension) const {
// The names of overdue logs.
Expand Down Expand Up @@ -1460,7 +1460,8 @@ bool LogCleaner::IsLogFromCurrentProject(const string& filepath,
return true;
}

bool LogCleaner::IsLogLastModifiedOver(const string& filepath, int days) const {
bool LogCleaner::IsLogLastModifiedOver(const string& filepath,
unsigned int days) const {
// Try to get the last modified time of this file.
struct stat file_stat;

Expand Down Expand Up @@ -2550,7 +2551,7 @@ void ShutdownGoogleLogging() {
logging_directories_list = NULL;
}

void EnableLogCleaner(int overdue_days) {
void EnableLogCleaner(unsigned int overdue_days) {
log_cleaner.Enable(overdue_days);
}

Expand Down