-
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
Make LogCleaner support relative paths #654
Conversation
I've also discovered this: google::SetLogDestination(google::INFO, "./"); // creates logs under process's cwd
// example: 20210518-122553.954758
google::SetLogDestination(google::INFO, "."); // also creates logs under process's cwd, but filenames starts with "."
// example: .20210518-122537.954584 Another example: google::SetLogDestination(google::INFO, "/tmp/"); // creates logs under /tmp/
google::SetLogDestination(google::INFO, "/tmp"); // creates logs under / with filenames starting with "tmp" Therefore, I think the correct way of setting log destination to "." is Please tell me if I've missed anything in the documentation. Thanks. |
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.
I believe there should be no difference between
google::SetLogDestination(google::INFO, "./");
and
google::SetLogDestination(google::INFO, ".");
since .
and ./
are both directories. However, this will require decomposing the path to determine the directory and the base filename.
src/logging.cc
Outdated
|
||
string filepath = ent->d_name; | ||
|
||
if (log_directory.at(log_directory.size() - 1) == dir_delim_) { |
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.
at
throws an out of range access. This should be avoided.
src/logging.cc
Outdated
@@ -1435,19 +1439,19 @@ bool LogCleaner::IsLogFromCurrentProject(const string& filepath, | |||
for (size_t i = cleaned_base_filename.size(); i < real_filepath_size; i++) { | |||
const char& c = filepath[i]; | |||
|
|||
if (i <= cleaned_base_filename.size() + 7) { // 0 ~ 7 : YYYYMMDD | |||
if (i <= cleaned_base_filename.size() + 7) { // 0 ~ 7 : YYYYMMDD |
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.
These formatting changes seem to be unrelated. I would undo them.
Any progress? |
@aesophor There are some conflicts now. Could you please rebase? |
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@googlebot I consent. |
0c0e592
to
40f461c
Compare
@aesophor Thanks. That's not necessary anymore; I already addressed all the open points. After careful consideration, the basenames Although not directly related to this PR, I encountered some problems writing unit tests for the log cleaner:
|
Closes #653
In #653, the user reports that the following usage of glog API:
will lead to an uncaught out_of_range exception.
This is caused by a bug in
LogCleaner::Run()
wherebase_filename
doesn't end with a "/".glog/src/logging.cc
Lines 1334 to 1335 in 0b3d4cb
This PR:
base_filename
inLogCleaner::Run()
ends with a "/", and if not, then we simply pass the relative path toLogCleaner::GetOverdueLogNames()
.LogCleaner::GetOverdueLogNames
, we only concatenatelog_directory
andent->d_name
iflog_directory
ends with a "/". Otherwise, just pass the relative path toLogCleaner::IsLogFromCurrentProject
.