blob: e1d18e08897a57a77909309accc49de67eca2c6d [file] [log] [blame]
Niels Möllerd8b9ed72019-05-08 13:53:51 +02001/*
2 * Copyright (c) 2017 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
11#ifndef API_RTC_EVENT_LOG_OUTPUT_FILE_H_
12#define API_RTC_EVENT_LOG_OUTPUT_FILE_H_
13
14#include <stddef.h>
15#include <stdio.h>
16#include <string>
17
18#include "api/rtc_event_log_output.h"
Niels Möllerd8b9ed72019-05-08 13:53:51 +020019#include "rtc_base/system/file_wrapper.h"
20
21namespace webrtc {
22
23class RtcEventLogOutputFile final : public RtcEventLogOutput {
24 public:
25 static const size_t kMaxReasonableFileSize; // Explanation at declaration.
26
27 // Unlimited/limited-size output file (by filename).
28 explicit RtcEventLogOutputFile(const std::string& file_name);
29 RtcEventLogOutputFile(const std::string& file_name, size_t max_size_bytes);
30
31 // Limited-size output file (by FILE*). This class takes ownership
32 // of the FILE*, and closes it on destruction.
33 RtcEventLogOutputFile(FILE* file, size_t max_size_bytes);
34
Niels Möllerd8b9ed72019-05-08 13:53:51 +020035 ~RtcEventLogOutputFile() override = default;
36
37 bool IsActive() const override;
38
39 bool Write(const std::string& output) override;
40
41 private:
42 RtcEventLogOutputFile(FileWrapper file, size_t max_size_bytes);
43
44 // IsActive() can be called either from outside or from inside, but we don't
45 // want to incur the overhead of a virtual function call if called from inside
46 // some other function of this class.
47 inline bool IsActiveInternal() const;
48
49 // Maximum size, or zero for no limit.
50 const size_t max_size_bytes_;
51 size_t written_bytes_{0};
52 FileWrapper file_;
53};
54
55} // namespace webrtc
56
57#endif // API_RTC_EVENT_LOG_OUTPUT_FILE_H_