xref: /aosp_15_r20/external/webrtc/test/logging/file_log_writer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2019 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 TEST_LOGGING_FILE_LOG_WRITER_H_
11 #define TEST_LOGGING_FILE_LOG_WRITER_H_
12 
13 #include <cstdio>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "absl/strings/string_view.h"
19 #include "test/logging/log_writer.h"
20 
21 namespace webrtc {
22 namespace webrtc_impl {
23 class FileLogWriter final : public RtcEventLogOutput {
24  public:
25   explicit FileLogWriter(absl::string_view file_path);
26   ~FileLogWriter() final;
27   bool IsActive() const override;
28   bool Write(absl::string_view value) override;
29   void Flush() override;
30 
31  private:
32   std::FILE* const out_;
33 };
34 }  // namespace webrtc_impl
35 class FileLogWriterFactory final : public LogWriterFactoryInterface {
36  public:
37   explicit FileLogWriterFactory(absl::string_view base_path);
38   ~FileLogWriterFactory() final;
39 
40   std::unique_ptr<RtcEventLogOutput> Create(
41       absl::string_view filename) override;
42 
43  private:
44   const std::string base_path_;
45   std::vector<std::unique_ptr<webrtc_impl::FileLogWriter>> writers_;
46 };
47 
48 }  // namespace webrtc
49 
50 #endif  // TEST_LOGGING_FILE_LOG_WRITER_H_
51