blob: 62a93b85a86aa1146c066f57795c83ecf69d26bc [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef RTC_BASE_LOG_SINKS_H_
12#define RTC_BASE_LOG_SINKS_H_
tkchin93411912015-07-22 12:12:17 -070013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020016#include <memory>
17#include <string>
tkchin93411912015-07-22 12:12:17 -070018
Ali Tofigh6364d082022-03-14 13:32:04 +010019#include "absl/strings/string_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/file_rotating_stream.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/logging.h"
tkchin93411912015-07-22 12:12:17 -070022
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020023namespace 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 16:03:14 +020029 // `num_log_files` must be greater than 1 and `max_log_size` must be greater
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020030 // than 0.
Ali Tofigh2ab914c2022-04-13 12:55:15 +020031 FileRotatingLogSink(absl::string_view log_dir_path,
32 absl::string_view log_prefix,
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020033 size_t max_log_size,
34 size_t num_log_files);
35 ~FileRotatingLogSink() override;
36
Byoungchan Lee14af7622022-01-12 05:24:58 +090037 FileRotatingLogSink(const FileRotatingLogSink&) = delete;
38 FileRotatingLogSink& operator=(const FileRotatingLogSink&) = delete;
39
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020040 // 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 13:32:04 +010043 void OnLogMessage(absl::string_view message) override;
Ali Tofigh8fcc79b2022-04-29 22:39:20 +020044 void OnLogMessage(const std::string& message,
45 LoggingSeverity sev,
46 const char* tag) override;
Ali Tofigh6364d082022-03-14 13:32:04 +010047 void OnLogMessage(absl::string_view message,
Paulina Hensmanf1e3cb42018-06-20 14:07:05 +020048 LoggingSeverity sev,
49 const char* tag) override;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020050
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 07:52:50 +020062};
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 12:55:15 +020068 CallSessionFileRotatingLogSink(absl::string_view log_dir_path,
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020069 size_t max_total_log_size);
70 ~CallSessionFileRotatingLogSink() override;
71
Byoungchan Lee14af7622022-01-12 05:24:58 +090072 CallSessionFileRotatingLogSink(const CallSessionFileRotatingLogSink&) =
73 delete;
74 CallSessionFileRotatingLogSink& operator=(
75 const CallSessionFileRotatingLogSink&) = delete;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020076};
77
78} // namespace rtc
79
Steve Anton10542f22019-01-11 09:11:00 -080080#endif // RTC_BASE_LOG_SINKS_H_