Package org.chsrobotics.lib.telemetry
Class Logger<T>
java.lang.Object
org.chsrobotics.lib.telemetry.Logger<T>
- Type Parameters:
T
- The data type of the log entry.
Utility to streamline publishing data to NetworkTables and saving it to an on-robot log file.
Parameterized to the type of data to publish/log.
If the data isn't numerical (Double, Int, Long, etc), Boolean, String, or an Array of one of
those types, this will instead publish and log the result of its .toString()
method.
This can generally be used in two ways: construction with a lambda of the logged value, or
passing the new value with every call of update()
.
Values are only flushed to NetworkTables and built-in logs when update()
is called.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Factory class to simplify creating many similar logs at once. -
Constructor Summary
ConstructorsConstructorDescriptionLogger
(edu.wpi.first.util.datalog.DataLog log, String key, String subdirName, boolean publishToNT, boolean recordInLog) Constructs a Logger using a provided DataLog, with the option of whether to publish to NT and the log.Constructs a Logger usingHighLevelLogger.getLog()
, publishing to NT and logging.Logger
(Supplier<T> lambda, edu.wpi.first.util.datalog.DataLog log, String key, String subdirName, boolean publishToNT, boolean recordInLog) Constructs a Logger using a provided DataLog, with the option of whether to publish to NT and the log.Constructs a Logger usingHighLevelLogger.getLog()
, publishing to NT and logging. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether this is publishing values to NetworkTables.boolean
Returns whether this is recording values to the on-robot log.void
Values will be pushed to NetworkTables.void
Values will be recorded to the on board data log.void
Values will not be pushed to NetworkTables.void
Values will not be recorded to the on board data log.void
update()
Updates data sinks with the current internal value.void
Updates data sinks with the given value.void
Updates data sinks with the given value.
-
Constructor Details
-
Logger
public Logger(Supplier<T> lambda, edu.wpi.first.util.datalog.DataLog log, String key, String subdirName, boolean publishToNT, boolean recordInLog) Constructs a Logger using a provided DataLog, with the option of whether to publish to NT and the log.- Parameters:
lambda
- Lambda (of logged type) to use as initial data source.log
- The DataLog to log values inside of, most likely fromHighLevelLogger.getInstance.getLog()
or whatever log is being used program-wide.key
- A string identifier for the logged field.subdirName
- The string name of the existing or new NetworkTables sub-table to write to.publishToNT
- Whether this should push logged values to NetworkTables.recordInLog
- Whether this should store logged values in an on-robot log file.
-
Logger
public Logger(edu.wpi.first.util.datalog.DataLog log, String key, String subdirName, boolean publishToNT, boolean recordInLog) Constructs a Logger using a provided DataLog, with the option of whether to publish to NT and the log.- Parameters:
log
- The DataLog to log values inside of, most likely fromHighLevelLogger.getInstance.getLog()
or whatever log is being used program-wide.key
- A string identifier for the logged field.subdirName
- The string name of the existing or new NetworkTables sub-table to write to.publishToNT
- Whether this should push logged values to NetworkTables.recordInLog
- Whether this should store logged values in an on-robot log file.
-
Logger
Constructs a Logger usingHighLevelLogger.getLog()
, publishing to NT and logging.- Parameters:
lambda
- Lambda (of logged type) to use as initial data source.key
- A string identifier for the logged field.subdirName
- The string name of the existing or new NetworkTables sub-table to write to.
-
Logger
Constructs a Logger usingHighLevelLogger.getLog()
, publishing to NT and logging.- Parameters:
key
- A string identifier for the logged field.subdirName
- The string name of the existing or new NetworkTables sub-table to write to.
-
-
Method Details
-
isPublishingToNT
public boolean isPublishingToNT()Returns whether this is publishing values to NetworkTables.- Returns:
- True new values are pushed to NetworkTables.
-
startPublishingToNT
public void startPublishingToNT()Values will be pushed to NetworkTables. -
stopPublishingToNT
public void stopPublishingToNT()Values will not be pushed to NetworkTables. -
isRecordingToLog
public boolean isRecordingToLog()Returns whether this is recording values to the on-robot log.- Returns:
- True if values are being recorded to the on board data log.
-
startRecordingToLog
public void startRecordingToLog()Values will be recorded to the on board data log. -
stopRecordingToLog
public void stopRecordingToLog()Values will not be recorded to the on board data log. -
update
public void update()Updates data sinks with the current internal value.If this was not constructed with a lambda and other
update()
methods have not been invoked, is a non-op. -
update
Updates data sinks with the given value.- Parameters:
value
- Instance of type T to store internally and send to data sinks.
-
update
Updates data sinks with the given value.- Parameters:
lambda
- Lambda of type T to store internally and send to data sinks.
-