WPILibC++ 2023.4.3-108-ge5452e3
DataLogManager.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 <string>
8#include <string_view>
9
10namespace wpi::log {
11class DataLog;
12} // namespace wpi::log
13
14namespace frc {
15
16/**
17 * Centralized data log that provides automatic data log file management. It
18 * automatically cleans up old files when disk space is low and renames the file
19 * based either on current date/time or (if available) competition match number.
20 * The deta file will be saved to a USB flash drive if one is attached, or to
21 * /home/lvuser otherwise.
22 *
23 * Log files are initially named "FRC_TBD_{random}.wpilog" until the DS
24 * connects. After the DS connects, the log file is renamed to
25 * "FRC_yyyyMMdd_HHmmss.wpilog" (where the date/time is UTC). If the FMS is
26 * connected and provides a match number, the log file is renamed to
27 * "FRC_yyyyMMdd_HHmmss_{event}_{match}.wpilog".
28 *
29 * On startup, all existing FRC_TBD log files are deleted. If there is less than
30 * 50 MB of free space on the target storage, FRC_ log files are deleted (oldest
31 * to newest) until there is 50 MB free OR there are 10 files remaining.
32 *
33 * By default, all NetworkTables value changes are stored to the data log.
34 */
35class DataLogManager final {
36 public:
37 DataLogManager() = delete;
38
39 /**
40 * Start data log manager. The parameters have no effect if the data log
41 * manager was already started (e.g. by calling another static function).
42 *
43 * @param dir if not empty, directory to use for data log storage
44 * @param filename filename to use; if none provided, the filename is
45 * automatically generated
46 * @param period time between automatic flushes to disk, in seconds;
47 * this is a time/storage tradeoff
48 */
49 static void Start(std::string_view dir = "", std::string_view filename = "",
50 double period = 0.25);
51
52 /**
53 * Log a message to the "messages" entry. The message is also printed to
54 * standard output (followed by a newline).
55 *
56 * @param message message
57 */
58 static void Log(std::string_view message);
59
60 /**
61 * Get the managed data log (for custom logging). Starts the data log manager
62 * if not already started.
63 *
64 * @return data log
65 */
67
68 /**
69 * Get the log directory.
70 *
71 * @return log directory
72 */
73 static std::string GetLogDir();
74
75 /**
76 * Enable or disable logging of NetworkTables data. Note that unlike the
77 * network interface for NetworkTables, this will capture every value change.
78 * Defaults to enabled.
79 *
80 * @param enabled true to enable, false to disable
81 */
82 static void LogNetworkTables(bool enabled);
83};
84
85} // namespace frc
Centralized data log that provides automatic data log file management.
Definition: DataLogManager.h:35
static wpi::log::DataLog & GetLog()
Get the managed data log (for custom logging).
static void LogNetworkTables(bool enabled)
Enable or disable logging of NetworkTables data.
static void Start(std::string_view dir="", std::string_view filename="", double period=0.25)
Start data log manager.
static std::string GetLogDir()
Get the log directory.
static void Log(std::string_view message)
Log a message to the "messages" entry.
A data log.
Definition: DataLog.h:66
basic_string_view< char > string_view
Definition: core.h:520
Definition: AprilTagPoseEstimator.h:15
Definition: ntcore_cpp.h:30