blob: 70d0299f0a590cbddb0b9869c0663acc14baa648 [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
Steve Anton10542f22019-01-11 17:11:0019#include "rtc_base/constructor_magic.h"
20#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:
29 // |num_log_files| must be greater than 1 and |max_log_size| must be greater
30 // than 0.
31 FileRotatingLogSink(const std::string& log_dir_path,
32 const std::string& log_prefix,
33 size_t max_log_size,
34 size_t num_log_files);
35 ~FileRotatingLogSink() override;
36
37 // Writes the message to the current file. It will spill over to the next
38 // file if needed.
39 void OnLogMessage(const std::string& message) override;
Paulina Hensmanf1e3cb42018-06-20 12:07:0540 void OnLogMessage(const std::string& message,
41 LoggingSeverity sev,
42 const char* tag) override;
Henrik Kjellanderec78f1c2017-06-29 05:52:5043
44 // Deletes any existing files in the directory and creates a new log file.
45 virtual bool Init();
46
47 // Disables buffering on the underlying stream.
48 bool DisableBuffering();
49
50 protected:
51 explicit FileRotatingLogSink(FileRotatingStream* stream);
52
53 private:
54 std::unique_ptr<FileRotatingStream> stream_;
55
56 RTC_DISALLOW_COPY_AND_ASSIGN(FileRotatingLogSink);
57};
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
67 private:
68 RTC_DISALLOW_COPY_AND_ASSIGN(CallSessionFileRotatingLogSink);
69};
70
71} // namespace rtc
72
Steve Anton10542f22019-01-11 17:11:0073#endif // RTC_BASE_LOG_SINKS_H_