tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "rtc_base/logsinks.h" |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 12 | |
Jonas Olsson | 55378f4 | 2018-05-25 08:23:10 | [diff] [blame] | 13 | #include <cstdio> |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
tkchin | 28bae02 | 2015-07-23 19:27:02 | [diff] [blame] | 17 | |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 18 | namespace rtc { |
| 19 | |
| 20 | FileRotatingLogSink::FileRotatingLogSink(const std::string& log_dir_path, |
| 21 | const std::string& log_prefix, |
| 22 | size_t max_log_size, |
| 23 | size_t num_log_files) |
| 24 | : FileRotatingLogSink(new FileRotatingStream(log_dir_path, |
| 25 | log_prefix, |
| 26 | max_log_size, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 27 | num_log_files)) {} |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 28 | |
| 29 | FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream) |
| 30 | : stream_(stream) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 31 | RTC_DCHECK(stream); |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 32 | } |
| 33 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 34 | FileRotatingLogSink::~FileRotatingLogSink() {} |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 35 | |
| 36 | void FileRotatingLogSink::OnLogMessage(const std::string& message) { |
tkchin | 28bae02 | 2015-07-23 19:27:02 | [diff] [blame] | 37 | if (stream_->GetState() != SS_OPEN) { |
Jonas Olsson | 55378f4 | 2018-05-25 08:23:10 | [diff] [blame] | 38 | std::fprintf(stderr, "Init() must be called before adding this sink.\n"); |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 39 | return; |
| 40 | } |
| 41 | stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr); |
| 42 | } |
| 43 | |
Paulina Hensman | f1e3cb4 | 2018-06-20 12:07:05 | [diff] [blame] | 44 | void FileRotatingLogSink::OnLogMessage(const std::string& message, |
| 45 | LoggingSeverity sev, |
| 46 | const char* tag) { |
| 47 | if (stream_->GetState() != SS_OPEN) { |
| 48 | std::fprintf(stderr, "Init() must be called before adding this sink.\n"); |
| 49 | return; |
| 50 | } |
| 51 | stream_->WriteAll(tag, strlen(tag), nullptr, nullptr); |
| 52 | stream_->WriteAll(": ", 2, nullptr, nullptr); |
| 53 | stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr); |
| 54 | } |
| 55 | |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 56 | bool FileRotatingLogSink::Init() { |
| 57 | return stream_->Open(); |
| 58 | } |
| 59 | |
tkchin | 28bae02 | 2015-07-23 19:27:02 | [diff] [blame] | 60 | bool FileRotatingLogSink::DisableBuffering() { |
| 61 | return stream_->DisableBuffering(); |
| 62 | } |
| 63 | |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 64 | CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink( |
| 65 | const std::string& log_dir_path, |
| 66 | size_t max_total_log_size) |
| 67 | : FileRotatingLogSink( |
| 68 | new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) { |
| 69 | } |
| 70 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 71 | CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {} |
tkchin | 9341191 | 2015-07-22 19:12:17 | [diff] [blame] | 72 | |
| 73 | } // namespace rtc |