blob: d2c286a86a48afb9b01edb5bff67d376c2395b29 [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
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/file_rotating_stream.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/logging.h"
tkchin93411912015-07-22 12:12:17 -070021
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020022namespace rtc {
23
24// Log sink that uses a FileRotatingStream to write to disk.
25// Init() must be called before adding this sink.
26class FileRotatingLogSink : public LogSink {
27 public:
Artem Titov96e3b992021-07-26 16:03:14 +020028 // `num_log_files` must be greater than 1 and `max_log_size` must be greater
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020029 // than 0.
30 FileRotatingLogSink(const std::string& log_dir_path,
31 const std::string& log_prefix,
32 size_t max_log_size,
33 size_t num_log_files);
34 ~FileRotatingLogSink() override;
35
Byoungchan Lee14af7622022-01-12 05:24:58 +090036 FileRotatingLogSink(const FileRotatingLogSink&) = delete;
37 FileRotatingLogSink& operator=(const FileRotatingLogSink&) = delete;
38
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020039 // Writes the message to the current file. It will spill over to the next
40 // file if needed.
41 void OnLogMessage(const std::string& message) override;
Paulina Hensmanf1e3cb42018-06-20 14:07:05 +020042 void OnLogMessage(const std::string& message,
43 LoggingSeverity sev,
44 const char* tag) override;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020045
46 // Deletes any existing files in the directory and creates a new log file.
47 virtual bool Init();
48
49 // Disables buffering on the underlying stream.
50 bool DisableBuffering();
51
52 protected:
53 explicit FileRotatingLogSink(FileRotatingStream* stream);
54
55 private:
56 std::unique_ptr<FileRotatingStream> stream_;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020057};
58
59// Log sink that uses a CallSessionFileRotatingStream to write to disk.
60// Init() must be called before adding this sink.
61class CallSessionFileRotatingLogSink : public FileRotatingLogSink {
62 public:
63 CallSessionFileRotatingLogSink(const std::string& log_dir_path,
64 size_t max_total_log_size);
65 ~CallSessionFileRotatingLogSink() override;
66
Byoungchan Lee14af7622022-01-12 05:24:58 +090067 CallSessionFileRotatingLogSink(const CallSessionFileRotatingLogSink&) =
68 delete;
69 CallSessionFileRotatingLogSink& operator=(
70 const CallSessionFileRotatingLogSink&) = delete;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020071};
72
73} // namespace rtc
74
Steve Anton10542f22019-01-11 09:11:00 -080075#endif // RTC_BASE_LOG_SINKS_H_