-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
add map between severity and overdue minutes #1144
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and apologies for the late reply.
The changes are going into the right direction. Please add some unit tests. For this, you can extend the existing log cleaner tests.
@@ -337,6 +338,16 @@ const char* GetLogSeverityName(LogSeverity severity) { | |||
return LogSeverityNames[severity]; | |||
} | |||
|
|||
LogSeverity FindFilepathLogSeverity(const std::string& filepath) { | |||
for (int i = GLOG_INFO; i < NUM_SEVERITIES; i++) { | |||
if (filepath.find(GetLogSeverityName(static_cast<LogSeverity>(i))) != std::string::npos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (filepath.find(GetLogSeverityName(static_cast<LogSeverity>(i))) != std::string::npos) { | |
if (filepath.rfind(GetLogSeverityName(static_cast<LogSeverity>(i))) != std::string::npos) { |
Search from right since the severity is used as a suffix.
return static_cast<LogSeverity>(i); | ||
} | ||
} | ||
// assume that the file has the INFO severity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not assume anything and simply return a not found sentinel.
@@ -1286,7 +1299,14 @@ LogCleaner::LogCleaner() = default; | |||
|
|||
void LogCleaner::Enable(const std::chrono::minutes& overdue) { | |||
enabled_ = true; | |||
overdue_ = overdue; | |||
for (int i = GLOG_INFO; i < NUM_SEVERITIES; i++) { | |||
overdue_per_severity_[static_cast<LogSeverity>(i)] = overdue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fill the map only with the severity set by the user.
@@ -2627,6 +2654,10 @@ void EnableLogCleaner(const std::chrono::minutes& overdue) { | |||
log_cleaner.Enable(overdue); | |||
} | |||
|
|||
void EnableLogCleaner(std::unordered_map<LogSeverity, std::chrono::minutes>& overdue_per_severity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing the map as a parameter makes the calls verbose and the API usage unnecessarily complicated. Instead use the following signature:
void EnableLogCleaner(std::unordered_map<LogSeverity, std::chrono::minutes>& overdue_per_severity) { | |
void EnableLogCleaner(LogSeverity severity, const std::chrono::minutes& overdue) { |
void EnableLogCleaner(std::unordered_map<LogSeverity, std::chrono::minutes>& overdue_per_severity) { | ||
log_cleaner.Enable(overdue_per_severity); | ||
} | ||
|
||
void DisableLogCleaner() { log_cleaner.Disable(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For symmetry, there should be an API call for disabling the log cleaner for specific severity.
I have added an
unordered_map
that can store a severity and it's corresponding overdue time to theLogCleaner
object. The modifications should be backwards compatible. If this idea is correct, we can preform some optimizations, like keeping a cache of filepaths whose severities have been computed.Fixes: #882