| 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 "rtc_base/checks.h" |
| 19 |
| 20 | namespace rtc { |
| 21 |
| 22 | FileRotatingLogSink::FileRotatingLogSink(const std::string& log_dir_path, |
| 23 | const std::string& log_prefix, |
| 24 | size_t max_log_size, |
| 25 | size_t num_log_files) |
| 26 | : FileRotatingLogSink(new FileRotatingStream(log_dir_path, |
| 27 | log_prefix, |
| 28 | max_log_size, |
| 29 | num_log_files)) {} |
| 30 |
| 31 | FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream) |
| 32 | : stream_(stream) { |
| 33 | RTC_DCHECK(stream); |
| 34 | } |
| 35 |
| 36 | FileRotatingLogSink::~FileRotatingLogSink() {} |
| 37 |
| 38 | void FileRotatingLogSink::OnLogMessage(const std::string& message) { |
| 39 | if (!stream_->IsOpen()) { |
| 40 | std::fprintf(stderr, "Init() must be called before adding this sink.\n"); |
| 41 | return; |
| 42 | } |
| 43 | stream_->Write(message.c_str(), message.size()); |
| 44 | } |
| 45 |
| 46 | void FileRotatingLogSink::OnLogMessage(const std::string& message, |
| 47 | LoggingSeverity sev, |
| 48 | const char* tag) { |
| 49 | if (!stream_->IsOpen()) { |
| 50 | std::fprintf(stderr, "Init() must be called before adding this sink.\n"); |
| 51 | return; |
| 52 | } |
| 53 | stream_->Write(tag, strlen(tag)); |
| 54 | stream_->Write(": ", 2); |
| 55 | stream_->Write(message.c_str(), message.size()); |
| 56 | } |
| 57 |
| 58 | bool FileRotatingLogSink::Init() { |
| 59 | return stream_->Open(); |
| 60 | } |
| 61 |
| 62 | bool FileRotatingLogSink::DisableBuffering() { |
| 63 | return stream_->DisableBuffering(); |
| 64 | } |
| 65 |
| 66 | CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink( |
| 67 | const std::string& log_dir_path, |
| 68 | size_t max_total_log_size) |
| 69 | : FileRotatingLogSink( |
| 70 | new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) { |
| 71 | } |
| 72 |
| 73 | CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {} |
| 74 |
| 75 | } // namespace rtc |
| 76 |