streamline constructor logic

and improve test for rotate_on_open=true
This commit is contained in:
Philip Miller
2019-01-24 00:06:15 -05:00
parent cce1e36e26
commit 3925f8fa16
2 changed files with 32 additions and 7 deletions

View File

@@ -36,9 +36,14 @@ public:
, max_size_(max_size)
, max_files_(max_files)
{
file_helper_.open(calc_filename(base_filename_, 0));
if (rotate_on_open)
rotate_();
{
rotate_(false);
}
else
{
file_helper_.open(calc_filename(base_filename_, 0));
}
current_size_ = file_helper_.size(); // expensive. called only once
}
@@ -90,7 +95,7 @@ private:
// log.1.txt -> log.2.txt
// log.2.txt -> log.3.txt
// log.3.txt -> delete
void rotate_()
void rotate_(bool reopen=true)
{
using details::os::filename_to_str;
file_helper_.close();
@@ -118,7 +123,14 @@ private:
}
}
}
file_helper_.reopen(true);
if (reopen)
{
file_helper_.reopen(true);
}
else
{
file_helper_.open(base_filename_, true);
}
}
// delete the target if exists, and rename the src file to target