Package dev.doglog
Class DogLog
java.lang.Object
dev.doglog.DogLog
A logger based on WPILib's
DataLogManager
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static boolean
Whether the logger is enabled.protected static final EpochLogger
protected static final LogQueuer
protected static DogLogOptions
The options to use for the logger.protected static final Tunable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
clearFault
(Enum<?> faultName) Reset the count of a fault to 0, and set the alert associated with the fault to inactive if possible.static void
clearFault
(String faultName) Reset the count of a fault to 0, and set the alert associated with the fault to inactive if possible.static void
decreaseFault
(Enum<?> faultName) Lower the count of a fault by 1, unless it is already at 0.static void
decreaseFault
(String faultName) Lower the count of a fault by 1, unless it is already at 0.static boolean
Check if any faults logged using logged usinglogFault(String)
are currently active.static boolean
Check if faults have been logged usinglogFault(String)
.static DogLogOptions
Get the options used by the logger.static boolean
Returns whether the logger is enabled.static void
Log a boolean.static void
Log a boolean array.static void
Log a double.static void
Log a double array.static void
Log a float.static void
Log a float array.static void
Log an int array.static void
Log a long.static void
Log a long array.static void
Log an enum.static void
Log an enum array.static void
Log a string.static void
Log a string array.static void
Log a string with a custom type string.static <T extends edu.wpi.first.util.struct.StructSerializable>
voidLog a struct.static <T extends edu.wpi.first.util.struct.StructSerializable>
voidLog a struct array.static void
Log a fault and create an error typeAlert
for it.static void
Log a fault and create an error typeAlert
for it.static void
Log a fault and create anAlert
for it at the specified level.static void
setEnabled
(boolean newEnabled) Set whether the logger is enabled.static void
setOptions
(DogLogOptions newOptions) Update the options used by the logger.static void
setPdh
(edu.wpi.first.wpilibj.PowerDistribution pdh) Set thePowerDistribution
instance to use for logging PDH/PDP data when logging extras is enabled.static void
Start a timer to track how long an operation takes to execute.static edu.wpi.first.wpilibj2.command.Command
Wraps aCommand
with a timer that records how long the command runs.static void
Stop a timer started withtime(String)
and log the duration in seconds to the specified key.static void
Log the current FPGA timestamp.static edu.wpi.first.networktables.BooleanSubscriber
Create a tunable boolean.static edu.wpi.first.networktables.BooleanSubscriber
Create a tunable boolean.static edu.wpi.first.networktables.DoubleSubscriber
Create a tunable double.static edu.wpi.first.networktables.DoubleSubscriber
tunable
(String key, double defaultValue, DoubleConsumer onChange) Create a tunable double.static edu.wpi.first.networktables.FloatSubscriber
Create a tunable float.static edu.wpi.first.networktables.FloatSubscriber
Create a tunable float.static edu.wpi.first.networktables.IntegerSubscriber
Create a tunable integer.static edu.wpi.first.networktables.IntegerSubscriber
tunable
(String key, long defaultValue, LongConsumer onChange) Create a tunable integer.static edu.wpi.first.networktables.StringSubscriber
Create a tunable string.static edu.wpi.first.networktables.StringSubscriber
Create a tunable string.
-
Field Details
-
options
The options to use for the logger. -
logger
-
enabled
protected static boolean enabledWhether the logger is enabled. -
tunable
-
epochLogger
-
-
Constructor Details
-
DogLog
protected DogLog()
-
-
Method Details
-
getOptions
Get the options used by the logger. -
setOptions
Update the options used by the logger.Example:
DogLog.setOptions(new DogLogOptions().withNtPublish(true));
See https://doglog.dev/reference/logger-options/ for more information.
-
setPdh
public static void setPdh(edu.wpi.first.wpilibj.PowerDistribution pdh) Set thePowerDistribution
instance to use for logging PDH/PDP data when logging extras is enabled. If this is set to `null`, no PDH data will be logged. Otherwise, information like battery voltage, device currents, etc. will be logged.Example:
DogLog.setPdh(new PowerDistribution());
- Parameters:
pdh
- ThePowerDistribution
instance to use for logging PDH/PDP data.
-
setEnabled
public static void setEnabled(boolean newEnabled) Set whether the logger is enabled. If the logger is not enabled, calls to `log()` functions will not do anything.By default, the logger is enabled.
-
isEnabled
public static boolean isEnabled()Returns whether the logger is enabled.- See Also:
-
log
Log a boolean array. -
log
Log a boolean. -
log
Log a double array. -
log
Log a double. -
log
Log a float array. -
log
Log a float. -
log
Log an int array. -
log
Log a long array. -
log
Log a long. -
log
Log a string array. -
log
Log an enum array. Enums will be converted to strings withEnum.name()
. -
log
Log a string. -
log
Log a string with a custom type string. -
log
Log an enum. The enum will be converted to a string withEnum.name()
. -
log
public static <T extends edu.wpi.first.util.struct.StructSerializable> void log(String key, T[] value) Log a struct array. -
log
public static <T extends edu.wpi.first.util.struct.StructSerializable> void log(String key, T value) Log a struct. -
logFault
Log a fault and create anAlert
for it at the specified level.See https://doglog.dev/guides/faults for more information.
- Parameters:
faultName
- The name of the fault to log.alertType
- The type of alert to create for the fault, ornull
if it should not create an alert- See Also:
-
logFault
Log a fault and create an error typeAlert
for it.See https://doglog.dev/guides/faults for more information.
- Parameters:
faultName
- The name of the fault to log.- See Also:
-
logFault
Log a fault and create an error typeAlert
for it. The enum will be converted to a string withEnum.name()
.See https://doglog.dev/guides/faults for more information.
- Parameters:
faultName
- The name of the fault to log.- See Also:
-
decreaseFault
Lower the count of a fault by 1, unless it is already at 0. If there is an alert associated with the fault, it will be set to inactive once the fault's count is 0.- Parameters:
faultName
- The name of the fault to decrement the count of.- See Also:
-
decreaseFault
Lower the count of a fault by 1, unless it is already at 0. If there is an alert associated with the fault, it will be set to inactive once the fault's count is 0.- Parameters:
faultName
- The name of the fault to decrement the count of.- See Also:
-
clearFault
Reset the count of a fault to 0, and set the alert associated with the fault to inactive if possible.- Parameters:
faultName
- The name of the fault to reset.
-
clearFault
Reset the count of a fault to 0, and set the alert associated with the fault to inactive if possible.- Parameters:
faultName
- The name of the fault to reset.
-
faultsLogged
public static boolean faultsLogged()Check if faults have been logged usinglogFault(String)
.- Returns:
- Whether any faults have been logged.
-
faultsActive
public static boolean faultsActive()Check if any faults logged using logged usinglogFault(String)
are currently active.- Returns:
- Whether any faults are currently active.
-
timestamp
Log the current FPGA timestamp. Useful for recording each time a block of code is executed, since timestamps are unique and monotonically increasing.- Parameters:
key
- The key to log the timestamp to.
-
time
Start a timer to track how long an operation takes to execute. When you calltimeEnd(String)
the duration of the operation in seconds will be logged to the specified key.- Parameters:
key
- The key to start the timer for.- See Also:
-
time
public static edu.wpi.first.wpilibj2.command.Command time(String key, edu.wpi.first.wpilibj2.command.Command command) Wraps aCommand
with a timer that records how long the command runs. The command name will be copied with a prefix of "Timed".- Parameters:
key
- The key to log the duration of the command to.command
- The command to wrap.- See Also:
-
timeEnd
Stop a timer started withtime(String)
and log the duration in seconds to the specified key.- Parameters:
key
- The key to stop the timer for.- See Also:
-
tunable
Create a tunable double.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.- Returns:
- A
DoubleSubscriber
used to retrieve the tunable value.
-
tunable
public static edu.wpi.first.networktables.DoubleSubscriber tunable(String key, double defaultValue, DoubleConsumer onChange) Create a tunable double.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.onChange
- A function to call when the tunable value changes.- Returns:
- A
DoubleSubscriber
used to retrieve the tunable value.
-
tunable
Create a tunable float.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.- Returns:
- A
FloatSubscriber
used to retrieve the tunable value.
-
tunable
public static edu.wpi.first.networktables.FloatSubscriber tunable(String key, float defaultValue, edu.wpi.first.util.function.FloatConsumer onChange) Create a tunable float.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.onChange
- A function to call when the tunable value changes.- Returns:
- A
FloatSubscriber
used to retrieve the tunable value.
-
tunable
public static edu.wpi.first.networktables.BooleanSubscriber tunable(String key, boolean defaultValue) Create a tunable boolean.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.- Returns:
- A
BooleanSubscriber
used to retrieve the tunable value.
-
tunable
public static edu.wpi.first.networktables.BooleanSubscriber tunable(String key, boolean defaultValue, edu.wpi.first.util.function.BooleanConsumer onChange) Create a tunable boolean.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.onChange
- A function to call when the tunable value changes.- Returns:
- A
BooleanSubscriber
used to retrieve the tunable value.
-
tunable
Create a tunable string.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.- Returns:
- A
StringSubscriber
used to retrieve the tunable value.
-
tunable
public static edu.wpi.first.networktables.StringSubscriber tunable(String key, String defaultValue, Consumer<String> onChange) Create a tunable string.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.onChange
- A function to call when the tunable value changes.- Returns:
- A
StringSubscriber
used to retrieve the tunable value.
-
tunable
Create a tunable integer.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.- Returns:
- An
IntegerSubscriber
used to retrieve the tunable value.
-
tunable
public static edu.wpi.first.networktables.IntegerSubscriber tunable(String key, long defaultValue, LongConsumer onChange) Create a tunable integer.- Parameters:
key
- The key for the tunable value.defaultValue
- The default value for the tunable value.onChange
- A function to call when the tunable value changes.- Returns:
- An
IntegerSubscriber
used to retrieve the tunable value.
-