rtc_event_log_output_file.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  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. #ifndef API_RTC_EVENT_LOG_OUTPUT_FILE_H_
  11. #define API_RTC_EVENT_LOG_OUTPUT_FILE_H_
  12. #include <stddef.h>
  13. #include <stdio.h>
  14. #include <string>
  15. #include "api/rtc_event_log_output.h"
  16. #include "rtc_base/system/file_wrapper.h"
  17. namespace webrtc {
  18. class RtcEventLogOutputFile final : public RtcEventLogOutput {
  19. public:
  20. static const size_t kMaxReasonableFileSize; // Explanation at declaration.
  21. // Unlimited/limited-size output file (by filename).
  22. explicit RtcEventLogOutputFile(const std::string& file_name);
  23. RtcEventLogOutputFile(const std::string& file_name, size_t max_size_bytes);
  24. // Limited-size output file (by FILE*). This class takes ownership
  25. // of the FILE*, and closes it on destruction.
  26. RtcEventLogOutputFile(FILE* file, size_t max_size_bytes);
  27. ~RtcEventLogOutputFile() override = default;
  28. bool IsActive() const override;
  29. bool Write(const std::string& output) override;
  30. private:
  31. RtcEventLogOutputFile(FileWrapper file, size_t max_size_bytes);
  32. // IsActive() can be called either from outside or from inside, but we don't
  33. // want to incur the overhead of a virtual function call if called from inside
  34. // some other function of this class.
  35. inline bool IsActiveInternal() const;
  36. // Maximum size, or zero for no limit.
  37. const size_t max_size_bytes_;
  38. size_t written_bytes_{0};
  39. FileWrapper file_;
  40. };
  41. } // namespace webrtc
  42. #endif // API_RTC_EVENT_LOG_OUTPUT_FILE_H_