OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 FileRotatingStream::FileRotatingStream(const std::string& dir_path, | 31 FileRotatingStream::FileRotatingStream(const std::string& dir_path, |
32 const std::string& file_prefix, | 32 const std::string& file_prefix, |
33 size_t max_file_size, | 33 size_t max_file_size, |
34 size_t num_files) | 34 size_t num_files) |
35 : FileRotatingStream(dir_path, | 35 : FileRotatingStream(dir_path, |
36 file_prefix, | 36 file_prefix, |
37 max_file_size, | 37 max_file_size, |
38 num_files, | 38 num_files, |
39 kWrite) { | 39 kWrite) { |
40 RTC_DCHECK_GT(max_file_size, 0u); | 40 RTC_DCHECK_GT(max_file_size, 0); |
41 RTC_DCHECK_GT(num_files, 1u); | 41 RTC_DCHECK_GT(num_files, 1); |
42 } | 42 } |
43 | 43 |
44 FileRotatingStream::FileRotatingStream(const std::string& dir_path, | 44 FileRotatingStream::FileRotatingStream(const std::string& dir_path, |
45 const std::string& file_prefix, | 45 const std::string& file_prefix, |
46 size_t max_file_size, | 46 size_t max_file_size, |
47 size_t num_files, | 47 size_t num_files, |
48 Mode mode) | 48 Mode mode) |
49 : dir_path_(dir_path), | 49 : dir_path_(dir_path), |
50 file_prefix_(file_prefix), | 50 file_prefix_(file_prefix), |
51 mode_(mode), | 51 mode_(mode), |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 // Opens the appropriate file in the appropriate mode. | 242 // Opens the appropriate file in the appropriate mode. |
243 RTC_DCHECK_LT(current_file_index_, file_names_.size()); | 243 RTC_DCHECK_LT(current_file_index_, file_names_.size()); |
244 std::string file_path = file_names_[current_file_index_]; | 244 std::string file_path = file_names_[current_file_index_]; |
245 file_stream_.reset(new FileStream()); | 245 file_stream_.reset(new FileStream()); |
246 const char* mode = nullptr; | 246 const char* mode = nullptr; |
247 switch (mode_) { | 247 switch (mode_) { |
248 case kWrite: | 248 case kWrite: |
249 mode = "w+"; | 249 mode = "w+"; |
250 // We should always we writing to the zero-th file. | 250 // We should always we writing to the zero-th file. |
251 RTC_DCHECK_EQ(current_file_index_, 0u); | 251 RTC_DCHECK_EQ(current_file_index_, 0); |
252 break; | 252 break; |
253 case kRead: | 253 case kRead: |
254 mode = "r"; | 254 mode = "r"; |
255 break; | 255 break; |
256 } | 256 } |
257 int error = 0; | 257 int error = 0; |
258 if (!file_stream_->Open(file_path, mode, &error)) { | 258 if (!file_stream_->Open(file_path, mode, &error)) { |
259 std::cerr << "Failed to open: " << file_path << "Error: " << error | 259 std::cerr << "Failed to open: " << file_path << "Error: " << error |
260 << std::endl; | 260 << std::endl; |
261 file_stream_.reset(); | 261 file_stream_.reset(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 353 |
354 CallSessionFileRotatingStream::CallSessionFileRotatingStream( | 354 CallSessionFileRotatingStream::CallSessionFileRotatingStream( |
355 const std::string& dir_path, | 355 const std::string& dir_path, |
356 size_t max_total_log_size) | 356 size_t max_total_log_size) |
357 : FileRotatingStream(dir_path, | 357 : FileRotatingStream(dir_path, |
358 kLogPrefix, | 358 kLogPrefix, |
359 max_total_log_size / 2, | 359 max_total_log_size / 2, |
360 GetNumRotatingLogFiles(max_total_log_size) + 1), | 360 GetNumRotatingLogFiles(max_total_log_size) + 1), |
361 max_total_log_size_(max_total_log_size), | 361 max_total_log_size_(max_total_log_size), |
362 num_rotations_(0) { | 362 num_rotations_(0) { |
363 RTC_DCHECK_GE(max_total_log_size, 4u); | 363 RTC_DCHECK_GE(max_total_log_size, 4); |
364 } | 364 } |
365 | 365 |
366 const char* CallSessionFileRotatingStream::kLogPrefix = "webrtc_log"; | 366 const char* CallSessionFileRotatingStream::kLogPrefix = "webrtc_log"; |
367 const size_t CallSessionFileRotatingStream::kRotatingLogFileDefaultSize = | 367 const size_t CallSessionFileRotatingStream::kRotatingLogFileDefaultSize = |
368 1024 * 1024; | 368 1024 * 1024; |
369 | 369 |
370 void CallSessionFileRotatingStream::OnRotation() { | 370 void CallSessionFileRotatingStream::OnRotation() { |
371 ++num_rotations_; | 371 ++num_rotations_; |
372 if (num_rotations_ == 1) { | 372 if (num_rotations_ == 1) { |
373 // On the first rotation adjust the max file size so subsequent files after | 373 // On the first rotation adjust the max file size so subsequent files after |
(...skipping 17 matching lines...) Expand all Loading... |
391 | 391 |
392 size_t CallSessionFileRotatingStream::GetNumRotatingLogFiles( | 392 size_t CallSessionFileRotatingStream::GetNumRotatingLogFiles( |
393 size_t max_total_log_size) { | 393 size_t max_total_log_size) { |
394 // At minimum have two rotating files. Otherwise split the available log size | 394 // At minimum have two rotating files. Otherwise split the available log size |
395 // evenly across 1MB files. | 395 // evenly across 1MB files. |
396 return std::max((size_t)2, | 396 return std::max((size_t)2, |
397 (max_total_log_size / 2) / kRotatingLogFileDefaultSize); | 397 (max_total_log_size / 2) / kRotatingLogFileDefaultSize); |
398 } | 398 } |
399 | 399 |
400 } // namespace rtc | 400 } // namespace rtc |
OLD | NEW |