| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #include "rtc_base/log_sinks.h" |
| 12 |
| 13 | #include <string.h> |
| 14 |
| 15 | #include <cstdio> |
| 16 | #include <string> |
| 17 |
| 18 | #include "absl/strings/string_view.h" |
| 19 | #include "rtc_base/checks.h" |
| 20 |
| 21 | namespace rtc { |
| 22 |
| 23 | FileRotatingLogSink::FileRotatingLogSink(absl::string_view log_dir_path, |
| 24 | absl::string_view log_prefix, |
| 25 | size_t max_log_size, |
| 26 | size_t num_log_files) |
| 27 | : FileRotatingLogSink(new FileRotatingStream(log_dir_path, |
| 28 | log_prefix, |
| 29 | max_log_size, |
| 30 | num_log_files)) {} |
| 31 |
| 32 | FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream) |
| 33 | : stream_(stream) { |
| 34 | RTC_DCHECK(stream); |
| 35 | } |
| 36 |
| 37 | FileRotatingLogSink::~FileRotatingLogSink() {} |
| 38 |
| 39 | void FileRotatingLogSink::OnLogMessage(const std::string& message) { |
| 40 | OnLogMessage(absl::string_view(message)); |
| 41 | } |
| 42 |
| 43 | void FileRotatingLogSink::OnLogMessage(absl::string_view message) { |
| 44 | if (!stream_->IsOpen()) { |
| 45 | std::fprintf(stderr, "Init() must be called before adding this sink.\n"); |
| 46 | return; |
| 47 | } |
| 48 | stream_->Write(message.data(), message.size()); |
| 49 | } |
| 50 |
| 51 | void FileRotatingLogSink::OnLogMessage(const std::string& message, |
| 52 | LoggingSeverity sev, |
| 53 | const char* tag) { |
| 54 | OnLogMessage(absl::string_view(message), sev, tag); |
| 55 | } |
| 56 |
| 57 | void FileRotatingLogSink::OnLogMessage(absl::string_view message, |
| 58 | LoggingSeverity sev, |
| 59 | const char* tag) { |
| 60 | if (!stream_->IsOpen()) { |
| 61 | std::fprintf(stderr, "Init() must be called before adding this sink.\n"); |
| 62 | return; |
| 63 | } |
| 64 | stream_->Write(tag, strlen(tag)); |
| 65 | stream_->Write(": ", 2); |
| 66 | stream_->Write(message.data(), message.size()); |
| 67 | } |
| 68 |
| 69 | bool FileRotatingLogSink::Init() { |
| 70 | return stream_->Open(); |
| 71 | } |
| 72 |
| 73 | bool FileRotatingLogSink::DisableBuffering() { |
| 74 | return stream_->DisableBuffering(); |
| 75 | } |
| 76 |
| 77 | CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink( |
| 78 | absl::string_view log_dir_path, |
| 79 | size_t max_total_log_size) |
| 80 | : FileRotatingLogSink( |
| 81 | new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) { |
| 82 | } |
| 83 |
| 84 | CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {} |
| 85 |
| 86 | } // namespace rtc |
| 87 |