-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Pwm1234/rotate on open #958
Conversation
when true, the log file will be rotated when it is opened so the newly constructed file will start off being empty
Is this pull request acceptable to be merged into the main v1.x branch? |
There was a review comment that i think is improtant to fix |
I am sorry, but I am not sure what review comment needs to be fixed. Can give me a link? |
@@ -31,12 +31,14 @@ template<typename Mutex> | |||
class rotating_file_sink final : public base_sink<Mutex> | |||
{ | |||
public: | |||
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files) | |||
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open=false) | |||
: base_filename_(std::move(base_filename)) | |||
, max_size_(max_size) | |||
, max_files_(max_files) | |||
{ | |||
file_helper_.open(calc_filename(base_filename_, 0)); |
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.
can be optimized. why open and then immediately close in rotate?
and improve test for rotate_on_open=true
I tried to address your comment. The optimization did introduce a little more complexity, but I think the changes are reasonable. I also updated to the latest v1.x commit. Are there other changes you want in this PR? |
I was thinking about something simpler (without modifying rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open=false)
: base_filename_(std::move(base_filename))
, max_size_(max_size)
, max_files_(max_files)
{
if (rotate_on_open)
{
rotate_();
current_size_ = 0;
}
else
{
file_helper_.open(calc_filename(base_filename_, 0));
current_size_ = file_helper_.size(); // expensive. called only once
}
}
|
But the modification to |
Good point. Let's leave out the optimization then. Maybe later we'll find a way to optimize without complicating the |
I agree that the minor optimization is not worth the complexity. I made a commit that removes the undesirable complexity with |
Merged. Thanks @pwm1234 |
add argument to rotating file sink for rotate_on_open
This change adds logic to the
rotating_file_sink
constructor so the caller can control whether or not the log file is rotated at initialization. This change provides new functionality when the optional argumentrotate_on_open
is true the log file will be rotated first, so the current log begins in a new file. An old log file will be lost only if the maximum number has already been reached.This is a refresh of PR #823.