tkchin | 9341191 | 2015-07-22 12:12:17 -0700 | [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 | |
| 11 | #include "webrtc/base/logsinks.h" |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | namespace rtc { |
| 16 | |
| 17 | FileRotatingLogSink::FileRotatingLogSink(const std::string& log_dir_path, |
| 18 | const std::string& log_prefix, |
| 19 | size_t max_log_size, |
| 20 | size_t num_log_files) |
| 21 | : FileRotatingLogSink(new FileRotatingStream(log_dir_path, |
| 22 | log_prefix, |
| 23 | max_log_size, |
| 24 | num_log_files)) { |
| 25 | } |
| 26 | |
| 27 | FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream) |
| 28 | : stream_(stream) { |
| 29 | } |
| 30 | |
| 31 | FileRotatingLogSink::~FileRotatingLogSink() { |
| 32 | } |
| 33 | |
| 34 | void FileRotatingLogSink::OnLogMessage(const std::string& message) { |
| 35 | if (!stream_ || stream_->GetState() != SS_OPEN) { |
| 36 | LOG(LS_WARNING) << "Init() must be called before adding this sink."; |
| 37 | return; |
| 38 | } |
| 39 | stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr); |
| 40 | } |
| 41 | |
| 42 | bool FileRotatingLogSink::Init() { |
| 43 | return stream_->Open(); |
| 44 | } |
| 45 | |
| 46 | CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink( |
| 47 | const std::string& log_dir_path, |
| 48 | size_t max_total_log_size) |
| 49 | : FileRotatingLogSink( |
| 50 | new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) { |
| 51 | } |
| 52 | |
| 53 | CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() { |
| 54 | } |
| 55 | |
| 56 | } // namespace rtc |