blob: 662b1f20de9785c75360840aa5ee8b09c7d9e717 [file] [log] [blame]
tkchin93411912015-07-22 19:12:171/*
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 04:47:3111#include "rtc_base/logsinks.h"
tkchin93411912015-07-22 19:12:1712
Jonas Olsson55378f42018-05-25 08:23:1013#include <cstdio>
tkchin93411912015-07-22 19:12:1714#include <string>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "rtc_base/checks.h"
tkchin28bae022015-07-23 19:27:0217
tkchin93411912015-07-22 19:12:1718namespace 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 13:03:0527 num_log_files)) {}
tkchin93411912015-07-22 19:12:1728
29FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream)
30 : stream_(stream) {
henrikg91d6ede2015-09-17 07:24:3431 RTC_DCHECK(stream);
tkchin93411912015-07-22 19:12:1732}
33
Yves Gerey665174f2018-06-19 13:03:0534FileRotatingLogSink::~FileRotatingLogSink() {}
tkchin93411912015-07-22 19:12:1735
36void FileRotatingLogSink::OnLogMessage(const std::string& message) {
tkchin28bae022015-07-23 19:27:0237 if (stream_->GetState() != SS_OPEN) {
Jonas Olsson55378f42018-05-25 08:23:1038 std::fprintf(stderr, "Init() must be called before adding this sink.\n");
tkchin93411912015-07-22 19:12:1739 return;
40 }
41 stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr);
42}
43
Paulina Hensmanf1e3cb42018-06-20 12:07:0544void 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
tkchin93411912015-07-22 19:12:1756bool FileRotatingLogSink::Init() {
57 return stream_->Open();
58}
59
tkchin28bae022015-07-23 19:27:0260bool FileRotatingLogSink::DisableBuffering() {
61 return stream_->DisableBuffering();
62}
63
tkchin93411912015-07-22 19:12:1764CallSessionFileRotatingLogSink::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 Gerey665174f2018-06-19 13:03:0571CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {}
tkchin93411912015-07-22 19:12:1772
73} // namespace rtc