int size = GetFileSize(file_name_);
if (size > rotation_size_)
- Rotate();
+ if (!Rotate())
+ return;
std::ofstream ofs(file_name_.c_str(), std::ios::app);
ofs << log_stream_->str();
log_stream_->clear();
}
-void FileLogBackend::Rotate() {
+bool FileLogBackend::Rotate() {
for (int i = max_rotation_; i > 0; i--) {
std::string old_log = file_name_ + "." + std::to_string(i);
// the oldest log will be removed
if (i == max_rotation_) {
- std::remove(old_log.c_str());
+ if (std::remove(old_log.c_str()) != 0)
+ return false;
} else {
std::string new_log = file_name_ + "." + std::to_string(i + 1);
- std::rename(old_log.c_str(), new_log.c_str());
+ if (std::rename(old_log.c_str(), new_log.c_str()) != 0)
+ return false;
}
}
std::string new_log = file_name_ + ".1";
- std::rename(file_name_.c_str(), new_log.c_str());
+ if (std::rename(file_name_.c_str(), new_log.c_str()) != 0)
+ return false;
+
+ return true;
}
int FileLogBackend::GetFileSize(const std::string& file_name) {