blob: d5febee9489ffff5b85576b5b1d647f3d3a11fa1 [file] [log] [blame]
tkchin93411912015-07-22 12:12:17 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/logsinks.h"
tkchin93411912015-07-22 12:12:17 -070012
Jonas Olsson55378f42018-05-25 10:23:10 +020013#include <cstdio>
tkchin93411912015-07-22 12:12:17 -070014#include <string>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/checks.h"
tkchin28bae022015-07-23 12:27:02 -070017
tkchin93411912015-07-22 12:12:17 -070018namespace rtc {
19
20FileRotatingLogSink::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 Gerey665174f2018-06-19 15:03:05 +020027 num_log_files)) {}
tkchin93411912015-07-22 12:12:17 -070028
29FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream)
30 : stream_(stream) {
henrikg91d6ede2015-09-17 00:24:34 -070031 RTC_DCHECK(stream);
tkchin93411912015-07-22 12:12:17 -070032}
33
Yves Gerey665174f2018-06-19 15:03:05 +020034FileRotatingLogSink::~FileRotatingLogSink() {}
tkchin93411912015-07-22 12:12:17 -070035
36void FileRotatingLogSink::OnLogMessage(const std::string& message) {
tkchin28bae022015-07-23 12:27:02 -070037 if (stream_->GetState() != SS_OPEN) {
Jonas Olsson55378f42018-05-25 10:23:10 +020038 std::fprintf(stderr, "Init() must be called before adding this sink.\n");
tkchin93411912015-07-22 12:12:17 -070039 return;
40 }
41 stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr);
42}
43
44bool FileRotatingLogSink::Init() {
45 return stream_->Open();
46}
47
tkchin28bae022015-07-23 12:27:02 -070048bool FileRotatingLogSink::DisableBuffering() {
49 return stream_->DisableBuffering();
50}
51
tkchin93411912015-07-22 12:12:17 -070052CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink(
53 const std::string& log_dir_path,
54 size_t max_total_log_size)
55 : FileRotatingLogSink(
56 new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) {
57}
58
Yves Gerey665174f2018-06-19 15:03:05 +020059CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {}
tkchin93411912015-07-22 12:12:17 -070060
61} // namespace rtc