WPILibC++ 2024.3.2
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 data file will be saved to a USB flash drive in a folder named "logs" if
21 * one is attached, or to /home/lvuser/logs 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 * Stop data log manager.
54 */
55 static void Stop();
56
57 /**
58 * Log a message to the "messages" entry. The message is also printed to
59 * standard output (followed by a newline).
60 *
61 * @param message message
62 */
63 static void Log(std::string_view message);
64
65 /**
66 * Get the managed data log (for custom logging). Starts the data log manager
67 * if not already started.
68 *
69 * @return data log
70 */
72
73 /**
74 * Get the log directory.
75 *
76 * @return log directory
77 */
78 static std::string GetLogDir();
79
80 /**
81 * Enable or disable logging of NetworkTables data. Note that unlike the
82 * network interface for NetworkTables, this will capture every value change.
83 * Defaults to enabled.
84 *
85 * @param enabled true to enable, false to disable
86 */
87 static void LogNetworkTables(bool enabled);
88};
89
90} // 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.
static void Stop()
Stop data log manager.
A data log.
Definition: DataLog.h:90
basic_string_view< char > string_view
Definition: core.h:501
Definition: AprilTagPoseEstimator.h:15
Definition: ntcore_cpp.h:31