WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
DataLogWriter.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8#include <string_view>
9#include <system_error>
10
12
13namespace wpi::util {
14class raw_ostream;
15class Logger;
16} // namespace wpi::util
17
18namespace wpi::log {
19
20/**
21 * A data log writer that flushes the data log to a file when Flush() is called.
22 *
23 * The lifetime of this object must be longer than any data log entry objects
24 * that refer to it.
25 */
26class DataLogWriter final : public DataLog {
27 public:
28 /**
29 * Constructs with a filename.
30 *
31 * @param filename filename to use
32 * @param ec error code if failed to open file (output)
33 * @param extraHeader extra header data
34 */
35 explicit DataLogWriter(std::string_view filename, std::error_code& ec,
36 std::string_view extraHeader = "");
37
38 /**
39 * Construct with a filename.
40 *
41 * @param msglog message logger
42 * @param filename filename to use
43 * @param ec error code if failed to open file (output)
44 * @param extraHeader extra header data
45 */
46 DataLogWriter(wpi::util::Logger& msglog, std::string_view filename,
47 std::error_code& ec, std::string_view extraHeader = "");
48
49 /**
50 * Constructs with an output stream.
51 *
52 * @param os output stream
53 * @param extraHeader extra header data
54 */
55 explicit DataLogWriter(std::unique_ptr<wpi::util::raw_ostream> os,
56 std::string_view extraHeader = "");
57
58 /**
59 * Constructs with an output stream.
60 *
61 * @param msglog message logger
62 * @param os output stream
63 * @param extraHeader extra header data
64 */
66 std::unique_ptr<wpi::util::raw_ostream> os,
67 std::string_view extraHeader = "");
68
70 DataLogWriter(const DataLogWriter&) = delete;
71 DataLogWriter& operator=(const DataLogWriter&) = delete;
73 DataLogWriter& operator=(const DataLogWriter&&) = delete;
74
75 /**
76 * Flushes the log data to disk.
77 */
78 void Flush() final;
79
80 /**
81 * Stops appending all records to the log, and closes the log file.
82 */
83 void Stop() final;
84
85 /**
86 * Gets the output stream.
87 *
88 * @return output stream
89 */
90 wpi::util::raw_ostream& GetStream() { return *m_os; }
91
92 private:
93 bool BufferFull() final;
94
95 std::unique_ptr<wpi::util::raw_ostream> m_os;
96};
97
98} // namespace wpi::log
DataLog(const DataLog &)=delete
virtual bool BufferFull()=0
Called when internal buffers reach the maximum count.
wpi::util::raw_ostream & GetStream()
Gets the output stream.
Definition DataLogWriter.hpp:90
DataLogWriter(wpi::util::Logger &msglog, std::string_view filename, std::error_code &ec, std::string_view extraHeader="")
Construct with a filename.
DataLogWriter(std::unique_ptr< wpi::util::raw_ostream > os, std::string_view extraHeader="")
Constructs with an output stream.
DataLogWriter(wpi::util::Logger &msglog, std::unique_ptr< wpi::util::raw_ostream > os, std::string_view extraHeader="")
Constructs with an output stream.
void Flush() final
Flushes the log data to disk.
DataLogWriter(std::string_view filename, std::error_code &ec, std::string_view extraHeader="")
Constructs with a filename.
void Stop() final
Stops appending all records to the log, and closes the log file.
Definition Logger.hpp:26
Definition StringMap.hpp:773
Definition DataLogReader.hpp:17
Definition raw_os_ostream.hpp:19
Definition CvSource.hpp:15