blob: db12e9f09bbaeeb9044a7cb74a3b90477177612c [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
Steve Anton10542f22019-01-11 17:11:0011#include "rtc_base/log_sinks.h"
tkchin93411912015-07-22 19:12:1712
Yves Gerey988cc082018-10-23 10:03:0113#include <string.h>
Jonas Olsson55378f42018-05-25 08:23:1014#include <cstdio>
tkchin93411912015-07-22 19:12:1715#include <string>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "rtc_base/checks.h"
Yves Gerey988cc082018-10-23 10:03:0118#include "rtc_base/stream.h"
tkchin28bae022015-07-23 19:27:0219
tkchin93411912015-07-22 19:12:1720namespace rtc {
21
22FileRotatingLogSink::FileRotatingLogSink(const std::string& log_dir_path,
23 const std::string& log_prefix,
24 size_t max_log_size,
25 size_t num_log_files)
26 : FileRotatingLogSink(new FileRotatingStream(log_dir_path,
27 log_prefix,
28 max_log_size,
Yves Gerey665174f2018-06-19 13:03:0529 num_log_files)) {}
tkchin93411912015-07-22 19:12:1730
31FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream)
32 : stream_(stream) {
henrikg91d6ede2015-09-17 07:24:3433 RTC_DCHECK(stream);
tkchin93411912015-07-22 19:12:1734}
35
Yves Gerey665174f2018-06-19 13:03:0536FileRotatingLogSink::~FileRotatingLogSink() {}
tkchin93411912015-07-22 19:12:1737
38void FileRotatingLogSink::OnLogMessage(const std::string& message) {
tkchin28bae022015-07-23 19:27:0239 if (stream_->GetState() != SS_OPEN) {
Jonas Olsson55378f42018-05-25 08:23:1040 std::fprintf(stderr, "Init() must be called before adding this sink.\n");
tkchin93411912015-07-22 19:12:1741 return;
42 }
43 stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr);
44}
45
Paulina Hensmanf1e3cb42018-06-20 12:07:0546void FileRotatingLogSink::OnLogMessage(const std::string& message,
47 LoggingSeverity sev,
48 const char* tag) {
49 if (stream_->GetState() != SS_OPEN) {
50 std::fprintf(stderr, "Init() must be called before adding this sink.\n");
51 return;
52 }
53 stream_->WriteAll(tag, strlen(tag), nullptr, nullptr);
54 stream_->WriteAll(": ", 2, nullptr, nullptr);
55 stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr);
56}
57
tkchin93411912015-07-22 19:12:1758bool FileRotatingLogSink::Init() {
59 return stream_->Open();
60}
61
tkchin28bae022015-07-23 19:27:0262bool FileRotatingLogSink::DisableBuffering() {
63 return stream_->DisableBuffering();
64}
65
tkchin93411912015-07-22 19:12:1766CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink(
67 const std::string& log_dir_path,
68 size_t max_total_log_size)
69 : FileRotatingLogSink(
70 new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) {
71}
72
Yves Gerey665174f2018-06-19 13:03:0573CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {}
tkchin93411912015-07-22 19:12:1774
75} // namespace rtc