blob: 62a93b85a86aa1146c066f57795c83ecf69d26bc [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#ifndef RTC_BASE_LOG_SINKS_H_
12#define RTC_BASE_LOG_SINKS_H_
tkchin93411912015-07-22 19:12:1713
Yves Gerey988cc082018-10-23 10:03:0114#include <stddef.h>
Jonas Olssona4d87372019-07-05 17:08:3315
Henrik Kjellanderec78f1c2017-06-29 05:52:5016#include <memory>
17#include <string>
tkchin93411912015-07-22 19:12:1718
Ali Tofigh6364d082022-03-14 12:32:0419#include "absl/strings/string_view.h"
Steve Anton10542f22019-01-11 17:11:0020#include "rtc_base/file_rotating_stream.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "rtc_base/logging.h"
tkchin93411912015-07-22 19:12:1722
Henrik Kjellanderec78f1c2017-06-29 05:52:5023namespace rtc {
24
25// Log sink that uses a FileRotatingStream to write to disk.
26// Init() must be called before adding this sink.
27class FileRotatingLogSink : public LogSink {
28 public:
Artem Titov96e3b992021-07-26 14:03:1429 // `num_log_files` must be greater than 1 and `max_log_size` must be greater
Henrik Kjellanderec78f1c2017-06-29 05:52:5030 // than 0.
Ali Tofigh2ab914c2022-04-13 10:55:1531 FileRotatingLogSink(absl::string_view log_dir_path,
32 absl::string_view log_prefix,
Henrik Kjellanderec78f1c2017-06-29 05:52:5033 size_t max_log_size,
34 size_t num_log_files);
35 ~FileRotatingLogSink() override;
36
Byoungchan Lee14af7622022-01-11 20:24:5837 FileRotatingLogSink(const FileRotatingLogSink&) = delete;
38 FileRotatingLogSink& operator=(const FileRotatingLogSink&) = delete;
39
Henrik Kjellanderec78f1c2017-06-29 05:52:5040 // Writes the message to the current file. It will spill over to the next
41 // file if needed.
42 void OnLogMessage(const std::string& message) override;
Ali Tofigh6364d082022-03-14 12:32:0443 void OnLogMessage(absl::string_view message) override;
Ali Tofigh8fcc79b2022-04-29 20:39:2044 void OnLogMessage(const std::string& message,
45 LoggingSeverity sev,
46 const char* tag) override;
Ali Tofigh6364d082022-03-14 12:32:0447 void OnLogMessage(absl::string_view message,
Paulina Hensmanf1e3cb42018-06-20 12:07:0548 LoggingSeverity sev,
49 const char* tag) override;
Henrik Kjellanderec78f1c2017-06-29 05:52:5050
51 // Deletes any existing files in the directory and creates a new log file.
52 virtual bool Init();
53
54 // Disables buffering on the underlying stream.
55 bool DisableBuffering();
56
57 protected:
58 explicit FileRotatingLogSink(FileRotatingStream* stream);
59
60 private:
61 std::unique_ptr<FileRotatingStream> stream_;
Henrik Kjellanderec78f1c2017-06-29 05:52:5062};
63
64// Log sink that uses a CallSessionFileRotatingStream to write to disk.
65// Init() must be called before adding this sink.
66class CallSessionFileRotatingLogSink : public FileRotatingLogSink {
67 public:
Ali Tofigh2ab914c2022-04-13 10:55:1568 CallSessionFileRotatingLogSink(absl::string_view log_dir_path,
Henrik Kjellanderec78f1c2017-06-29 05:52:5069 size_t max_total_log_size);
70 ~CallSessionFileRotatingLogSink() override;
71
Byoungchan Lee14af7622022-01-11 20:24:5872 CallSessionFileRotatingLogSink(const CallSessionFileRotatingLogSink&) =
73 delete;
74 CallSessionFileRotatingLogSink& operator=(
75 const CallSessionFileRotatingLogSink&) = delete;
Henrik Kjellanderec78f1c2017-06-29 05:52:5076};
77
78} // namespace rtc
79
Steve Anton10542f22019-01-11 17:11:0080#endif // RTC_BASE_LOG_SINKS_H_