blob: d0867a22024bbd15e7eddf8455c3c97dd0f9614c [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_LOGSINKS_H_
12#define RTC_BASE_LOGSINKS_H_
tkchin93411912015-07-22 12:12:17 -070013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020015#include <memory>
16#include <string>
tkchin93411912015-07-22 12:12:17 -070017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/constructormagic.h"
19#include "rtc_base/filerotatingstream.h"
20#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:
28 // |num_log_files| must be greater than 1 and |max_log_size| must be greater
29 // 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
36 // Writes the message to the current file. It will spill over to the next
37 // file if needed.
38 void OnLogMessage(const std::string& message) override;
Paulina Hensmanf1e3cb42018-06-20 14:07:05 +020039 void OnLogMessage(const std::string& message,
40 LoggingSeverity sev,
41 const char* tag) override;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020042
43 // Deletes any existing files in the directory and creates a new log file.
44 virtual bool Init();
45
46 // Disables buffering on the underlying stream.
47 bool DisableBuffering();
48
49 protected:
50 explicit FileRotatingLogSink(FileRotatingStream* stream);
51
52 private:
53 std::unique_ptr<FileRotatingStream> stream_;
54
55 RTC_DISALLOW_COPY_AND_ASSIGN(FileRotatingLogSink);
56};
57
58// Log sink that uses a CallSessionFileRotatingStream to write to disk.
59// Init() must be called before adding this sink.
60class CallSessionFileRotatingLogSink : public FileRotatingLogSink {
61 public:
62 CallSessionFileRotatingLogSink(const std::string& log_dir_path,
63 size_t max_total_log_size);
64 ~CallSessionFileRotatingLogSink() override;
65
66 private:
67 RTC_DISALLOW_COPY_AND_ASSIGN(CallSessionFileRotatingLogSink);
68};
69
70} // namespace rtc
71
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020072#endif // RTC_BASE_LOGSINKS_H_