WPILibC++ 2025.0.0-alpha-1-14-g3b6f38d
DataLogWriter.h
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
11#include "wpi/DataLog.h"
12
13namespace wpi {
14class raw_ostream;
15class Logger;
16} // namespace wpi
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 */
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::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 */
65 DataLogWriter(wpi::Logger& msglog, std::unique_ptr<wpi::raw_ostream> os,
66 std::string_view extraHeader = "");
67
69 DataLogWriter(const DataLogWriter&) = delete;
70 DataLogWriter& operator=(const DataLogWriter&) = delete;
72 DataLogWriter& operator=(const DataLogWriter&&) = delete;
73
74 /**
75 * Flushes the log data to disk.
76 */
77 void Flush() final;
78
79 /**
80 * Stops appending all records to the log, and closes the log file.
81 */
82 void Stop() final;
83
84 private:
85 bool BufferFull() final;
86
87 std::unique_ptr<wpi::raw_ostream> m_os;
88};
89
90} // namespace wpi::log
Definition: Logger.h:27
A data log for high-speed writing of data values.
Definition: DataLog.h:68
A data log writer that flushes the data log to a file when Flush() is called.
Definition: DataLogWriter.h:26
DataLogWriter(wpi::Logger &msglog, std::unique_ptr< wpi::raw_ostream > os, std::string_view extraHeader="")
Constructs with an output stream.
DataLogWriter(std::unique_ptr< wpi::raw_ostream > os, std::string_view extraHeader="")
Constructs with an output stream.
DataLogWriter(wpi::Logger &msglog, std::string_view filename, std::error_code &ec, std::string_view extraHeader="")
Construct with a filename.
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:43
Implement std::hash so that hash_code can be used in STL containers.
Definition: array.h:89
Definition: ntcore_cpp.h:31
Definition: ntcore_cpp.h:26
basic_string_view< char > string_view
Definition: base.h:601