Fix log size after rotation.

This commit is contained in:
levlam 2022-11-29 17:39:46 +03:00
parent 4f737910ab
commit b11a5b8ad4
2 changed files with 12 additions and 2 deletions

View File

@ -49,7 +49,12 @@ Status AsyncFileLog::init(string path, int64 rotate_threshold, bool redirect_std
if (!Stderr().empty() && redirect_stderr) { if (!Stderr().empty() && redirect_stderr) {
fd.get_native_fd().duplicate(Stderr().get_native_fd()).ignore(); fd.get_native_fd().duplicate(Stderr().get_native_fd()).ignore();
} }
size = 0; auto r_size = fd.get_size();
if (r_fd.is_error()) {
process_fatal_error(PSLICE() << "Failed to get log size: " << r_fd.error() << " in " << __FILE__ << " at "
<< __LINE__ << '\n');
}
size = r_size.move_as_ok();
}; };
auto append = [&](CSlice slice) { auto append = [&](CSlice slice) {
if (size > rotate_threshold) { if (size > rotate_threshold) {

View File

@ -128,7 +128,12 @@ void FileLog::do_after_rotation() {
if (!Stderr().empty() && redirect_stderr_) { if (!Stderr().empty() && redirect_stderr_) {
fd_.get_native_fd().duplicate(Stderr().get_native_fd()).ignore(); fd_.get_native_fd().duplicate(Stderr().get_native_fd()).ignore();
} }
size_ = 0; auto r_size = fd_.get_size();
if (r_fd.is_error()) {
process_fatal_error(PSLICE() << "Failed to get log size: " << r_fd.error() << " in " << __FILE__ << " at "
<< __LINE__ << '\n');
}
size_ = r_size.move_as_ok();
} }
Result<unique_ptr<LogInterface>> FileLog::create(string path, int64 rotate_threshold, bool redirect_stderr) { Result<unique_ptr<LogInterface>> FileLog::create(string path, int64 rotate_threshold, bool redirect_stderr) {