tkchin | f53dd28 | 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 | |
| 11 | #include "webrtc/base/logsinks.h" |
| 12 | |
tkchin | 9ccd4d8 | 2015-07-23 19:27:02 | [diff] [blame] | 13 | #include <iostream> |
tkchin | f53dd28 | 2015-07-22 19:12:17 | [diff] [blame] | 14 | #include <string> |
| 15 | |
tkchin | 9ccd4d8 | 2015-07-23 19:27:02 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
| 17 | |
tkchin | f53dd28 | 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, |
| 27 | num_log_files)) { |
| 28 | } |
| 29 | |
| 30 | FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream) |
| 31 | : stream_(stream) { |
henrikg | 5c075c8 | 2015-09-17 07:24:34 | [diff] [blame] | 32 | RTC_DCHECK(stream); |
tkchin | f53dd28 | 2015-07-22 19:12:17 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | FileRotatingLogSink::~FileRotatingLogSink() { |
| 36 | } |
| 37 | |
| 38 | void FileRotatingLogSink::OnLogMessage(const std::string& message) { |
tkchin | 9ccd4d8 | 2015-07-23 19:27:02 | [diff] [blame] | 39 | if (stream_->GetState() != SS_OPEN) { |
| 40 | std::cerr << "Init() must be called before adding this sink." << std::endl; |
tkchin | f53dd28 | 2015-07-22 19:12:17 | [diff] [blame] | 41 | return; |
| 42 | } |
| 43 | stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr); |
| 44 | } |
| 45 | |
| 46 | bool FileRotatingLogSink::Init() { |
| 47 | return stream_->Open(); |
| 48 | } |
| 49 | |
tkchin | 9ccd4d8 | 2015-07-23 19:27:02 | [diff] [blame] | 50 | bool FileRotatingLogSink::DisableBuffering() { |
| 51 | return stream_->DisableBuffering(); |
| 52 | } |
| 53 | |
tkchin | f53dd28 | 2015-07-22 19:12:17 | [diff] [blame] | 54 | CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink( |
| 55 | const std::string& log_dir_path, |
| 56 | size_t max_total_log_size) |
| 57 | : FileRotatingLogSink( |
| 58 | new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) { |
| 59 | } |
| 60 | |
| 61 | CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() { |
| 62 | } |
| 63 | |
| 64 | } // namespace rtc |