| 98 | } |
| 99 | |
| 100 | Status SimpleLogger::AppendEntry(const std::string& entry) { |
| 101 | DCHECK(initialized_); |
| 102 | lock_guard<mutex> l(log_file_lock_); |
| 103 | if (num_log_file_entries_ >= max_entries_per_file_) { |
| 104 | num_log_file_entries_ = 0; |
| 105 | // The log file is generated from a prefix and the timestamp in milliseconds. If |
| 106 | // the timestamp hasn't changed, then we continue logging to the same file. In that |
| 107 | // case, there is no need to enforce the limit on the number of log files. |
| 108 | string next_log_file_name = GenerateLogFileName(); |
| 109 | if (next_log_file_name != log_file_name_) { |
| 110 | log_file_name_ = next_log_file_name; |
| 111 | RETURN_IF_ERROR(FlushInternal()); |
| 112 | RotateLogFiles(); |
| 113 | } |
| 114 | } |
| 115 | if (!log_file_.is_open()) return Status("Log file is not open: " + log_file_name_); |
| 116 | // Not std::endl, since that causes an implicit flush |
| 117 | log_file_ << entry << "\n"; |
| 118 | ++num_log_file_entries_; |
| 119 | return Status::OK(); |
| 120 | } |
| 121 | |
| 122 | Status SimpleLogger::Flush() { |
| 123 | DCHECK(initialized_); |