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

RotatingFileHandler: Store complete path in '_created_files' #340

Merged
merged 1 commit into from
Aug 9, 2023
Merged
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
17 changes: 12 additions & 5 deletions quill/src/handlers/RotatingFileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ void RotatingFileHandler::_clean_and_recover_files(fs::path const& filename, std
continue;
}

std::string const extension = entry.path().extension().string(); // e.g. ".log"

// stem will be something like `logfile.1`
size_t pos = entry.path().stem().string().find_last_of('.');
if (pos != std::string::npos)
Expand All @@ -494,7 +496,9 @@ void RotatingFileHandler::_clean_and_recover_files(fs::path const& filename, std
std::string const index =
entry.path().stem().string().substr(pos + 1, entry.path().stem().string().length());

std::string const current_file = entry.path().filename().string().substr(0, pos) + ".log";
std::string const current_filename = entry.path().filename().string().substr(0, pos) + extension;
fs::path current_file = entry.path().parent_path();
current_file.append(current_filename);

// Attempt to convert the index to a number
QUILL_TRY
Expand All @@ -515,8 +519,9 @@ void RotatingFileHandler::_clean_and_recover_files(fs::path const& filename, std
if ((index_or_date.length() >= 8) && (index_or_date == today_date))
{
// assume it is a date, no need to find the index
std::string const current_file =
entry.path().filename().string().substr(0, pos) + ".log";
std::string const current_filename = entry.path().filename().string().substr(0, pos) + extension;
fs::path current_file = entry.path().parent_path();
current_file.append(current_filename);

_created_files.emplace_front(current_file, 0, index_or_date);
}
Expand All @@ -534,7 +539,9 @@ void RotatingFileHandler::_clean_and_recover_files(fs::path const& filename, std

if (date_part == today_date)
{
std::string const current_file = filename_with_date.substr(0, second_last) + ".log";
std::string const current_filename = filename_with_date.substr(0, second_last) + extension;
fs::path current_file = entry.path().parent_path();
current_file.append(current_filename);

// Attempt to convert the index to a number
QUILL_TRY
Expand All @@ -555,4 +562,4 @@ void RotatingFileHandler::_clean_and_recover_files(fs::path const& filename, std
[](FileInfo const& a, FileInfo const& b) { return a.index < b.index; });
}
}
} // namespace quill
} // namespace quill