tkchin | 9341191 | 2015-07-22 12:12:17 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_BASE_LOGSINKS_H_ |
| 12 | #define RTC_BASE_LOGSINKS_H_ |
tkchin | 9341191 | 2015-07-22 12:12:17 -0700 | [diff] [blame] | 13 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 14 | #include <memory> |
| 15 | #include <string> |
tkchin | 9341191 | 2015-07-22 12:12:17 -0700 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/constructormagic.h" |
| 18 | #include "rtc_base/filerotatingstream.h" |
| 19 | #include "rtc_base/logging.h" |
tkchin | 9341191 | 2015-07-22 12:12:17 -0700 | [diff] [blame] | 20 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 21 | namespace rtc { |
| 22 | |
| 23 | // Log sink that uses a FileRotatingStream to write to disk. |
| 24 | // Init() must be called before adding this sink. |
| 25 | class FileRotatingLogSink : public LogSink { |
| 26 | public: |
| 27 | // |num_log_files| must be greater than 1 and |max_log_size| must be greater |
| 28 | // than 0. |
| 29 | FileRotatingLogSink(const std::string& log_dir_path, |
| 30 | const std::string& log_prefix, |
| 31 | size_t max_log_size, |
| 32 | size_t num_log_files); |
| 33 | ~FileRotatingLogSink() override; |
| 34 | |
| 35 | // Writes the message to the current file. It will spill over to the next |
| 36 | // file if needed. |
| 37 | void OnLogMessage(const std::string& message) override; |
Paulina Hensman | f1e3cb4 | 2018-06-20 14:07:05 +0200 | [diff] [blame] | 38 | void OnLogMessage(const std::string& message, |
| 39 | LoggingSeverity sev, |
| 40 | const char* tag) override; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 41 | |
| 42 | // Deletes any existing files in the directory and creates a new log file. |
| 43 | virtual bool Init(); |
| 44 | |
| 45 | // Disables buffering on the underlying stream. |
| 46 | bool DisableBuffering(); |
| 47 | |
| 48 | protected: |
| 49 | explicit FileRotatingLogSink(FileRotatingStream* stream); |
| 50 | |
| 51 | private: |
| 52 | std::unique_ptr<FileRotatingStream> stream_; |
| 53 | |
| 54 | RTC_DISALLOW_COPY_AND_ASSIGN(FileRotatingLogSink); |
| 55 | }; |
| 56 | |
| 57 | // Log sink that uses a CallSessionFileRotatingStream to write to disk. |
| 58 | // Init() must be called before adding this sink. |
| 59 | class CallSessionFileRotatingLogSink : public FileRotatingLogSink { |
| 60 | public: |
| 61 | CallSessionFileRotatingLogSink(const std::string& log_dir_path, |
| 62 | size_t max_total_log_size); |
| 63 | ~CallSessionFileRotatingLogSink() override; |
| 64 | |
| 65 | private: |
| 66 | RTC_DISALLOW_COPY_AND_ASSIGN(CallSessionFileRotatingLogSink); |
| 67 | }; |
| 68 | |
| 69 | } // namespace rtc |
| 70 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 71 | #endif // RTC_BASE_LOGSINKS_H_ |