diff --git a/lib/src/main/java/dev/doglog/DogLog.java b/lib/src/main/java/dev/doglog/DogLog.java index 3841acb0..358f7853 100644 --- a/lib/src/main/java/dev/doglog/DogLog.java +++ b/lib/src/main/java/dev/doglog/DogLog.java @@ -82,18 +82,6 @@ public static void setOptions(@Nullable DogLogOptions newOptions) { if (!oldOptions.equals(newOptions)) { System.out.println("[DogLog] Options changed: " + newOptions); logger.setOptions(newOptions); - if (oldOptions.useLogThread() != newOptions.useLogThread()) { - // Create the new logger before we close the old one, to avoid race condition - var oldLogger = logger; - logger = LogWriterHighLevel.create(newOptions); - - try { - oldLogger.close(); - } catch (Exception e) { - System.err.println("[DogLog] Error closing old LogWriter instance:"); - e.printStackTrace(); - } - } tunable.setOptions(newOptions); } diff --git a/lib/src/main/java/dev/doglog/DogLogOptions.java b/lib/src/main/java/dev/doglog/DogLogOptions.java index cbdbac5e..eb6b46a4 100644 --- a/lib/src/main/java/dev/doglog/DogLogOptions.java +++ b/lib/src/main/java/dev/doglog/DogLogOptions.java @@ -28,21 +28,13 @@ public record DogLogOptions( boolean logExtras, /** Whether console output should be saved to the log file. */ boolean captureConsole, - /** The maximum size of the log entry queue to use. */ - int logEntryQueueCapacity, /** * A function that returns whether tunable values from NetworkTables should be used. Best * practice is to have this disabled when you are at competitions, to make robot behavior more * deterministic. The default behavior is to only use tunable values from NetworkTables when not * connected to the FMS on a competition field. */ - BooleanSupplier ntTunables, - /** - * Whether to use a separate thread to handle log entries. This setting defaults to true. - * Turning off the log thread may reduce the memory usage of logging, but could cause increased - * CPU load. - */ - boolean useLogThread) { + BooleanSupplier ntTunables) { private static boolean isNotOnFms() { return !DriverStation.isFMSAttached(); } @@ -59,8 +51,7 @@ private static boolean isNotOnFms() { */ public DogLogOptions() { // Default options - this( - DogLogOptions::isNotOnFms, false, false, true, true, 1000, DogLogOptions::isNotOnFms, true); + this(DogLogOptions::isNotOnFms, false, false, true, true, DogLogOptions::isNotOnFms); } /** @@ -95,14 +86,7 @@ public DogLogOptions withNtPublish(boolean ntPublish) { */ public DogLogOptions withNtPublish(BooleanSupplier ntPublish) { return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); + ntPublish, captureNt, captureDs, logExtras, captureConsole, ntTunables); } /** @@ -118,14 +102,7 @@ public DogLogOptions withNtPublish(BooleanSupplier ntPublish) { */ public DogLogOptions withCaptureNt(boolean captureNt) { return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); + ntPublish, captureNt, captureDs, logExtras, captureConsole, ntTunables); } /** @@ -141,14 +118,7 @@ public DogLogOptions withCaptureNt(boolean captureNt) { */ public DogLogOptions withCaptureDs(boolean captureDs) { return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); + ntPublish, captureNt, captureDs, logExtras, captureConsole, ntTunables); } /** @@ -165,38 +135,7 @@ public DogLogOptions withCaptureDs(boolean captureDs) { */ public DogLogOptions withLogExtras(boolean logExtras) { return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); - } - - /** - * Create a new options object, inheriting the configuration from this one, with {@link - * DogLogOptions#logEntryQueueCapacity} set to the provided value. - * - *

Example: - * - *

DogLog.setOptions(new DogLogOptions().withLogEntryQueueCapacity(1000));
- * - * @param logEntryQueueCapacity The size of the log message queue to use. - * @return A new options object with {@link DogLogOptions#logEntryQueueCapacity} set to the - * provided value. - */ - public DogLogOptions withLogEntryQueueCapacity(int logEntryQueueCapacity) { - return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); + ntPublish, captureNt, captureDs, logExtras, captureConsole, ntTunables); } /** @@ -213,14 +152,7 @@ public DogLogOptions withLogEntryQueueCapacity(int logEntryQueueCapacity) { */ public DogLogOptions withCaptureConsole(boolean captureConsole) { return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); + ntPublish, captureNt, captureDs, logExtras, captureConsole, ntTunables); } /** @@ -254,32 +186,6 @@ public DogLogOptions withNtTunables(boolean ntTunables) { */ public DogLogOptions withNtTunables(BooleanSupplier ntTunables) { return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); - } - - /** - * Create a new options object, inheriting the configuration from this one, with {@link - * DogLogOptions#useLogThread} set to the provided value. - * - * @param useLogThread Whether to use a separate thread to handle log entries. - * @return A new options object with {@link DogLogOptions#useLogThread} set to the provided value. - */ - public DogLogOptions withUseLogThread(boolean useLogThread) { - return new DogLogOptions( - ntPublish, - captureNt, - captureDs, - logExtras, - captureConsole, - logEntryQueueCapacity, - ntTunables, - useLogThread); + ntPublish, captureNt, captureDs, logExtras, captureConsole, ntTunables); } } diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/StructRegistry.java b/lib/src/main/java/dev/doglog/internal/StructRegistry.java similarity index 98% rename from lib/src/main/java/dev/doglog/internal/log_thread/StructRegistry.java rename to lib/src/main/java/dev/doglog/internal/StructRegistry.java index 057c2af7..de248c26 100644 --- a/lib/src/main/java/dev/doglog/internal/log_thread/StructRegistry.java +++ b/lib/src/main/java/dev/doglog/internal/StructRegistry.java @@ -1,4 +1,4 @@ -package dev.doglog.internal.log_thread; +package dev.doglog.internal; import edu.wpi.first.util.struct.Struct; import edu.wpi.first.util.struct.StructGenerator; diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/LogThread.java b/lib/src/main/java/dev/doglog/internal/log_thread/LogThread.java deleted file mode 100644 index 48056bec..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/LogThread.java +++ /dev/null @@ -1,103 +0,0 @@ -package dev.doglog.internal.log_thread; - -import dev.doglog.DogLogOptions; -import dev.doglog.internal.log_thread.entries.BaseQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.BooleanArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.BooleanQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.DoubleArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.DoubleArrayWithUnitQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.DoubleQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.DoubleWithUnitQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.EnumArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.EnumQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.FloatArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.FloatArrayWithUnitQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.FloatQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.FloatWithUnitQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.IntegerArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.IntegerArrayWithUnitQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.IntegerQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.IntegerWithUnitQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.RecordArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.RecordQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.StringArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.StringCustomTypeQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.StringQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.StructArrayQueuedLogEntry; -import dev.doglog.internal.log_thread.entries.StructQueuedLogEntry; -import dev.doglog.internal.log_thread.writers.CombinedWriter; -import edu.wpi.first.hal.HALUtil; -import edu.wpi.first.wpilibj.Timer; -import java.util.concurrent.BlockingQueue; - -/** A thread that processes queued log entries and writes them to the log file. */ -public class LogThread extends Thread { - private final BlockingQueue queue; - private final CombinedWriter logger; - private final Timer diagnosticsTimer = new Timer(); - - public LogThread(BlockingQueue queue, DogLogOptions initialOptions) { - super("DogLog LogThread"); - setDaemon(true); - - this.queue = queue; - - this.logger = new CombinedWriter(initialOptions); - - diagnosticsTimer.start(); - } - - public void setOptions(DogLogOptions options) { - logger.setOptions(options); - } - - @Override - public void run() { - System.out.println("[DogLog] LogThread started"); - logger.afterLogThreadStart(); - - try { - while (true) { - var entry = queue.take(); - - // TODO: Once the minimum Java version is 21, use pattern matching for switch expressions - // https://docs.oracle.com/en/java/javase/17/language/pattern-matching-switch-expressions-and-statements.html - switch (entry.type) { - case BOOLEAN -> ((BooleanQueuedLogEntry) entry).log(logger); - case BOOLEAN_ARRAY -> ((BooleanArrayQueuedLogEntry) entry).log(logger); - case DOUBLE -> ((DoubleQueuedLogEntry) entry).log(logger); - case DOUBLE_ARRAY -> ((DoubleArrayQueuedLogEntry) entry).log(logger); - case DOUBLE_WITH_UNIT -> ((DoubleWithUnitQueuedLogEntry) entry).log(logger); - case DOUBLE_ARRAY_WITH_UNIT -> ((DoubleArrayWithUnitQueuedLogEntry) entry).log(logger); - case FLOAT -> ((FloatQueuedLogEntry) entry).log(logger); - case FLOAT_ARRAY -> ((FloatArrayQueuedLogEntry) entry).log(logger); - case FLOAT_WITH_UNIT -> ((FloatWithUnitQueuedLogEntry) entry).log(logger); - case FLOAT_ARRAY_WITH_UNIT -> ((FloatArrayWithUnitQueuedLogEntry) entry).log(logger); - case INTEGER -> ((IntegerQueuedLogEntry) entry).log(logger); - case INTEGER_ARRAY -> ((IntegerArrayQueuedLogEntry) entry).log(logger); - case INTEGER_WITH_UNIT -> ((IntegerWithUnitQueuedLogEntry) entry).log(logger); - case INTEGER_ARRAY_WITH_UNIT -> ((IntegerArrayWithUnitQueuedLogEntry) entry).log(logger); - case STRING -> ((StringQueuedLogEntry) entry).log(logger); - case STRING_ARRAY -> ((StringArrayQueuedLogEntry) entry).log(logger); - case STRING_CUSTOM_TYPE -> ((StringCustomTypeQueuedLogEntry) entry).log(logger); - case STRUCT -> ((StructQueuedLogEntry) entry).log(logger); - case STRUCT_ARRAY -> ((StructArrayQueuedLogEntry) entry).log(logger); - case ENUM -> ((EnumQueuedLogEntry) entry).log(logger); - case ENUM_ARRAY -> ((EnumArrayQueuedLogEntry) entry).log(logger); - case RECORD -> ((RecordQueuedLogEntry) entry).log(logger); - case RECORD_ARRAY -> ((RecordArrayQueuedLogEntry) entry).log(logger); - } - - if (diagnosticsTimer.hasElapsed(DogLogOptions.LOOP_PERIOD_SECONDS)) { - diagnosticsTimer.reset(); - var now = HALUtil.getFPGATime(); - logger.log(now, "DogLog/QueuedLogs", false, queue.size()); - logger.log(now, "DogLog/QueueRemainingCapacity", false, queue.remainingCapacity()); - } - } - } catch (InterruptedException e) { - // Restore the interrupted status - Thread.currentThread().interrupt(); - } - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/BaseQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/BaseQueuedLogEntry.java deleted file mode 100644 index b8cf8030..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/BaseQueuedLogEntry.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public abstract class BaseQueuedLogEntry { - public final EntryType type; - public final String key; - public final boolean forceNt; - public final long timestamp; - - protected BaseQueuedLogEntry(EntryType type, String key, boolean forceNt, long timestamp) { - this.type = type; - this.key = key; - this.forceNt = forceNt; - this.timestamp = timestamp; - } - - public abstract void log(CombinedWriter writer); -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/BooleanArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/BooleanArrayQueuedLogEntry.java deleted file mode 100644 index 2720f209..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/BooleanArrayQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class BooleanArrayQueuedLogEntry extends BaseQueuedLogEntry { - public final boolean[] value; - - public BooleanArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, boolean[] value) { - super(EntryType.BOOLEAN_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/BooleanQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/BooleanQueuedLogEntry.java deleted file mode 100644 index 21067080..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/BooleanQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class BooleanQueuedLogEntry extends BaseQueuedLogEntry { - public final boolean value; - - public BooleanQueuedLogEntry(String key, boolean forceNt, long timestamp, boolean value) { - super(EntryType.BOOLEAN, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleArrayQueuedLogEntry.java deleted file mode 100644 index be5040a5..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleArrayQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class DoubleArrayQueuedLogEntry extends BaseQueuedLogEntry { - public final double[] value; - - public DoubleArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, double[] value) { - super(EntryType.DOUBLE_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleArrayWithUnitQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleArrayWithUnitQueuedLogEntry.java deleted file mode 100644 index 0082461b..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleArrayWithUnitQueuedLogEntry.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class DoubleArrayWithUnitQueuedLogEntry extends BaseQueuedLogEntry { - public final double[] value; - public final String unit; - - public DoubleArrayWithUnitQueuedLogEntry( - String key, boolean forceNt, long timestamp, double[] value, String unit) { - super(EntryType.DOUBLE_ARRAY_WITH_UNIT, key, forceNt, timestamp); - this.value = value; - this.unit = unit; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value, unit); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleQueuedLogEntry.java deleted file mode 100644 index 5bcfddca..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class DoubleQueuedLogEntry extends BaseQueuedLogEntry { - public final double value; - - public DoubleQueuedLogEntry(String key, boolean forceNt, long timestamp, double value) { - super(EntryType.DOUBLE, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleWithUnitQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleWithUnitQueuedLogEntry.java deleted file mode 100644 index 1700bb42..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/DoubleWithUnitQueuedLogEntry.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class DoubleWithUnitQueuedLogEntry extends BaseQueuedLogEntry { - public final double value; - public final String unit; - - public DoubleWithUnitQueuedLogEntry( - String key, boolean forceNt, long timestamp, double value, String unit) { - super(EntryType.DOUBLE_WITH_UNIT, key, forceNt, timestamp); - this.value = value; - this.unit = unit; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value, unit); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/EntryType.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/EntryType.java deleted file mode 100644 index 9ad18aff..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/EntryType.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -/** The type of a queued log entry. */ -public enum EntryType { - BOOLEAN_ARRAY, - BOOLEAN, - - DOUBLE_ARRAY, - DOUBLE, - DOUBLE_ARRAY_WITH_UNIT, - DOUBLE_WITH_UNIT, - - FLOAT_ARRAY, - FLOAT, - FLOAT_ARRAY_WITH_UNIT, - FLOAT_WITH_UNIT, - - INTEGER_ARRAY, - INTEGER, - INTEGER_ARRAY_WITH_UNIT, - INTEGER_WITH_UNIT, - - STRING_ARRAY, - STRING, - STRING_CUSTOM_TYPE, - - STRUCT_ARRAY, - STRUCT, - - ENUM_ARRAY, - ENUM, - - RECORD_ARRAY, - RECORD, -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/EnumArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/EnumArrayQueuedLogEntry.java deleted file mode 100644 index ff66df5f..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/EnumArrayQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class EnumArrayQueuedLogEntry> extends BaseQueuedLogEntry { - public final E[] value; - - public EnumArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, E[] value) { - super(EntryType.ENUM_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/EnumQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/EnumQueuedLogEntry.java deleted file mode 100644 index bea9a034..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/EnumQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class EnumQueuedLogEntry> extends BaseQueuedLogEntry { - public final E value; - - public EnumQueuedLogEntry(String key, boolean forceNt, long timestamp, E value) { - super(EntryType.ENUM, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatArrayQueuedLogEntry.java deleted file mode 100644 index f18a7487..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatArrayQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class FloatArrayQueuedLogEntry extends BaseQueuedLogEntry { - public final float[] value; - - public FloatArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, float[] value) { - super(EntryType.FLOAT_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatArrayWithUnitQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatArrayWithUnitQueuedLogEntry.java deleted file mode 100644 index ee86596e..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatArrayWithUnitQueuedLogEntry.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class FloatArrayWithUnitQueuedLogEntry extends BaseQueuedLogEntry { - public final float[] value; - public final String unit; - - public FloatArrayWithUnitQueuedLogEntry( - String key, boolean forceNt, long timestamp, float[] value, String unit) { - super(EntryType.FLOAT_ARRAY_WITH_UNIT, key, forceNt, timestamp); - this.value = value; - this.unit = unit; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value, unit); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatQueuedLogEntry.java deleted file mode 100644 index 644dc629..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class FloatQueuedLogEntry extends BaseQueuedLogEntry { - public final float value; - - public FloatQueuedLogEntry(String key, boolean forceNt, long timestamp, float value) { - super(EntryType.FLOAT, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatWithUnitQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatWithUnitQueuedLogEntry.java deleted file mode 100644 index 7e070ae2..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/FloatWithUnitQueuedLogEntry.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class FloatWithUnitQueuedLogEntry extends BaseQueuedLogEntry { - public final float value; - public final String unit; - - public FloatWithUnitQueuedLogEntry( - String key, boolean forceNt, long timestamp, float value, String unit) { - super(EntryType.FLOAT_WITH_UNIT, key, forceNt, timestamp); - this.value = value; - this.unit = unit; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value, unit); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerArrayQueuedLogEntry.java deleted file mode 100644 index 16fbbe2e..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerArrayQueuedLogEntry.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class IntegerArrayQueuedLogEntry extends BaseQueuedLogEntry { - public final long[] value; - - public IntegerArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, long[] value) { - super(EntryType.INTEGER_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - public IntegerArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, int[] value) { - this(key, forceNt, timestamp, new long[value.length]); - - for (int i = 0; i < value.length; i++) { - this.value[i] = value[i]; - } - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerArrayWithUnitQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerArrayWithUnitQueuedLogEntry.java deleted file mode 100644 index 6063e583..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerArrayWithUnitQueuedLogEntry.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class IntegerArrayWithUnitQueuedLogEntry extends BaseQueuedLogEntry { - public final long[] value; - public final String unit; - - public IntegerArrayWithUnitQueuedLogEntry( - String key, boolean forceNt, long timestamp, long[] value, String unit) { - super(EntryType.INTEGER_ARRAY_WITH_UNIT, key, forceNt, timestamp); - this.value = value; - this.unit = unit; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value, unit); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerQueuedLogEntry.java deleted file mode 100644 index fee01697..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class IntegerQueuedLogEntry extends BaseQueuedLogEntry { - public final long value; - - public IntegerQueuedLogEntry(String key, boolean forceNt, long timestamp, long value) { - super(EntryType.INTEGER, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerWithUnitQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerWithUnitQueuedLogEntry.java deleted file mode 100644 index d223dbd5..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/IntegerWithUnitQueuedLogEntry.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class IntegerWithUnitQueuedLogEntry extends BaseQueuedLogEntry { - public final long value; - public final String unit; - - public IntegerWithUnitQueuedLogEntry( - String key, boolean forceNt, long timestamp, long value, String unit) { - super(EntryType.INTEGER_WITH_UNIT, key, forceNt, timestamp); - this.value = value; - this.unit = unit; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value, unit); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/RecordArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/RecordArrayQueuedLogEntry.java deleted file mode 100644 index 512ed730..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/RecordArrayQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class RecordArrayQueuedLogEntry extends BaseQueuedLogEntry { - public final T[] value; - - public RecordArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, T[] value) { - super(EntryType.RECORD_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/RecordQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/RecordQueuedLogEntry.java deleted file mode 100644 index ee801f38..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/RecordQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class RecordQueuedLogEntry extends BaseQueuedLogEntry { - public final T value; - - public RecordQueuedLogEntry(String key, boolean forceNt, long timestamp, T value) { - super(EntryType.RECORD, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringArrayQueuedLogEntry.java deleted file mode 100644 index aaaf3254..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringArrayQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class StringArrayQueuedLogEntry extends BaseQueuedLogEntry { - public final String[] value; - - public StringArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, String[] value) { - super(EntryType.STRING_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringCustomTypeQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringCustomTypeQueuedLogEntry.java deleted file mode 100644 index 9fba64a6..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringCustomTypeQueuedLogEntry.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -// Custom class instead of just making StringQueuedLogEntry generic so that there's less runtime -// cost to check what kind of string log to do. -public class StringCustomTypeQueuedLogEntry extends BaseQueuedLogEntry { - public final String value; - public final String customTypeString; - - public StringCustomTypeQueuedLogEntry( - String key, boolean forceNt, long timestamp, String value, String customTypeString) { - super(EntryType.STRING_CUSTOM_TYPE, key, forceNt, timestamp); - this.value = value; - this.customTypeString = customTypeString; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value, customTypeString); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringQueuedLogEntry.java deleted file mode 100644 index 9d4dcc5c..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StringQueuedLogEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; - -public class StringQueuedLogEntry extends BaseQueuedLogEntry { - public final String value; - - public StringQueuedLogEntry(String key, boolean forceNt, long timestamp, String value) { - super(EntryType.STRING, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StructArrayQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/StructArrayQueuedLogEntry.java deleted file mode 100644 index 73581ac3..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StructArrayQueuedLogEntry.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; -import edu.wpi.first.util.struct.StructSerializable; - -public class StructArrayQueuedLogEntry extends BaseQueuedLogEntry { - public final T[] value; - - public StructArrayQueuedLogEntry(String key, boolean forceNt, long timestamp, T[] value) { - super(EntryType.STRUCT_ARRAY, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StructQueuedLogEntry.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/StructQueuedLogEntry.java deleted file mode 100644 index 022d695c..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/StructQueuedLogEntry.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.doglog.internal.log_thread.entries; - -import dev.doglog.internal.log_thread.writers.CombinedWriter; -import edu.wpi.first.util.struct.StructSerializable; - -public class StructQueuedLogEntry extends BaseQueuedLogEntry { - public final T value; - - public StructQueuedLogEntry(String key, boolean forceNt, long timestamp, T value) { - super(EntryType.STRUCT, key, forceNt, timestamp); - this.value = value; - } - - @Override - public void log(CombinedWriter writer) { - writer.log(timestamp, key, forceNt, value); - } -} diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/entries/package-info.java b/lib/src/main/java/dev/doglog/internal/log_thread/entries/package-info.java deleted file mode 100644 index 31d2eac8..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/entries/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Log entry classes. Rather than having a single generic class with a `Object value` field, we have - * separate classes for each type of log entry. This allows the JVM to optimize the code better, - * since casting from `Object` makes it harder for the JIT to work. - */ -@NullMarked -package dev.doglog.internal.log_thread.entries; - -import org.jspecify.annotations.NullMarked; diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/package-info.java b/lib/src/main/java/dev/doglog/internal/log_thread/package-info.java deleted file mode 100644 index 9f5d281a..00000000 --- a/lib/src/main/java/dev/doglog/internal/log_thread/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Code owned by the log thread. Nothing in here should be called by the main thread, or you risk - * blocking user code with logging operations. - */ -@NullMarked -package dev.doglog.internal.log_thread; - -import org.jspecify.annotations.NullMarked; diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/writers/CombinedWriter.java b/lib/src/main/java/dev/doglog/internal/writers/CombinedWriter.java similarity index 93% rename from lib/src/main/java/dev/doglog/internal/log_thread/writers/CombinedWriter.java rename to lib/src/main/java/dev/doglog/internal/writers/CombinedWriter.java index 856b645e..98effc21 100644 --- a/lib/src/main/java/dev/doglog/internal/log_thread/writers/CombinedWriter.java +++ b/lib/src/main/java/dev/doglog/internal/writers/CombinedWriter.java @@ -1,13 +1,10 @@ -package dev.doglog.internal.log_thread.writers; +package dev.doglog.internal.writers; -import dev.doglog.DogLog; import dev.doglog.DogLogOptions; -import dev.doglog.internal.log_thread.LogThread; -import dev.doglog.internal.log_thread.StructRegistry; +import dev.doglog.internal.StructRegistry; import edu.wpi.first.hal.HALUtil; import edu.wpi.first.util.struct.Struct; import edu.wpi.first.util.struct.StructSerializable; -import edu.wpi.first.wpilibj.Alert.AlertType; import java.util.Arrays; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NullMarked; @@ -264,16 +261,6 @@ public void setOptions(DogLogOptions options) { printOptions(); } - /** - * Runs code that may produce logs, and thus must be run once all DogLog init logic has been run. - * Using the {@link LogThread} start for this is a convenient way to run code at that point. - */ - public void afterLogThreadStart() { - if (!dataLogReporter.isLogDestinationValid()) { - DogLog.logFault("[DogLog] UNSAFE_LOG_DESTINATION", AlertType.kWarning); - } - } - private void printOptions() { var now = HALUtil.getFPGATime(); log(now, "DogLog/Options", false, options.toString()); diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/writers/DataLogWriter.java b/lib/src/main/java/dev/doglog/internal/writers/DataLogWriter.java similarity index 92% rename from lib/src/main/java/dev/doglog/internal/log_thread/writers/DataLogWriter.java rename to lib/src/main/java/dev/doglog/internal/writers/DataLogWriter.java index 8a561d05..3ee7ab49 100644 --- a/lib/src/main/java/dev/doglog/internal/log_thread/writers/DataLogWriter.java +++ b/lib/src/main/java/dev/doglog/internal/writers/DataLogWriter.java @@ -1,7 +1,6 @@ -package dev.doglog.internal.log_thread.writers; +package dev.doglog.internal.writers; import dev.doglog.DogLogOptions; -import dev.doglog.internal.writers.LogWriterLowLevel; import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.util.datalog.BooleanArrayLogEntry; import edu.wpi.first.util.datalog.BooleanLogEntry; @@ -20,8 +19,6 @@ import edu.wpi.first.util.struct.Struct; import edu.wpi.first.wpilibj.DataLogManager; import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.RobotBase; -import edu.wpi.first.wpilibj.RuntimeType; import java.util.HashMap; import java.util.Map; import org.jspecify.annotations.NullMarked; @@ -33,9 +30,6 @@ public class DataLogWriter implements LogWriterLowLevel { private static final String ENTRY_METADATA_UNITS_PREFIX = "{\"source\":\"DogLog\",\"unit\":\""; private static final String ENTRY_METADATA_UNITS_SUFFIX = "\"}"; - /** The directory path when logging to the flash storage on a roboRIO 1. */ - private static final String RIO1_DISK_LOG_DIR = "/home/lvuser/logs"; - private static String entryMetadataForUnit(String unit) { return ENTRY_METADATA_UNITS_PREFIX + unit + ENTRY_METADATA_UNITS_SUFFIX; } @@ -304,19 +298,6 @@ public void setOptions(DogLogOptions options) { } } - /** - * This could be a static method, but it's not because this class controls initializing {@link - * DataLogManager}, which has to be done before this method can be called. - * - * @return Whether the log destination directory is valid. On a roboRIO 2 this is always true, on - * a roboRIO 1 this is true when a USB drive is attached. - */ - public boolean isLogDestinationValid() { - // See DataLogManager#makeLogDir() for source on this logic - return !(RobotBase.getRuntimeType() == RuntimeType.kRoboRIO - && DataLogManager.getLogDir().equals(RIO1_DISK_LOG_DIR)); - } - private String prefixKey(String key) { return logTable + "/" + key; } diff --git a/lib/src/main/java/dev/doglog/internal/writers/LogWriter.java b/lib/src/main/java/dev/doglog/internal/writers/LogWriter.java index 3276ade3..299cf034 100644 --- a/lib/src/main/java/dev/doglog/internal/writers/LogWriter.java +++ b/lib/src/main/java/dev/doglog/internal/writers/LogWriter.java @@ -2,8 +2,6 @@ import dev.doglog.DogLogOptions; import dev.doglog.internal.extras.ExtrasLogger; -import dev.doglog.internal.log_thread.writers.CombinedWriter; -import edu.wpi.first.hal.HALUtil; import edu.wpi.first.util.struct.StructSerializable; import edu.wpi.first.wpilibj.PowerDistribution; import org.jspecify.annotations.NullMarked; @@ -17,13 +15,8 @@ public class LogWriter implements LogWriterHighLevel { public LogWriter(DogLogOptions initialOptions) { writer = new CombinedWriter(initialOptions); - writer.afterLogThreadStart(); extras = new ExtrasLogger(this, initialOptions); - - var now = HALUtil.getFPGATime(); - log(now, "DogLog/QueuedLogs", false, -1); - log(now, "DogLog/QueueRemainingCapacity", false, -1); } @Override diff --git a/lib/src/main/java/dev/doglog/internal/writers/LogWriterHighLevel.java b/lib/src/main/java/dev/doglog/internal/writers/LogWriterHighLevel.java index dfbb7961..d6192fd5 100644 --- a/lib/src/main/java/dev/doglog/internal/writers/LogWriterHighLevel.java +++ b/lib/src/main/java/dev/doglog/internal/writers/LogWriterHighLevel.java @@ -6,14 +6,11 @@ import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; -/** - * Consumes log entries provided by DogLog. Implementations decide how to process the log data (e.g. - * enqueueing for processing on a background thread or writing immediately). - */ +/** Consumes log entries provided by DogLog. Implementations decide how to process the log data. */ @NullMarked public interface LogWriterHighLevel extends LogWriterBase, AutoCloseable { public static LogWriterHighLevel create(DogLogOptions options) { - return options.useLogThread() ? new ThreadedLogWriter(options) : new LogWriter(options); + return new LogWriter(options); } public void setPdh(@Nullable PowerDistribution pdh); diff --git a/lib/src/main/java/dev/doglog/internal/log_thread/writers/NetworkTablesWriter.java b/lib/src/main/java/dev/doglog/internal/writers/NetworkTablesWriter.java similarity index 99% rename from lib/src/main/java/dev/doglog/internal/log_thread/writers/NetworkTablesWriter.java rename to lib/src/main/java/dev/doglog/internal/writers/NetworkTablesWriter.java index eceb5adc..46eecb43 100644 --- a/lib/src/main/java/dev/doglog/internal/log_thread/writers/NetworkTablesWriter.java +++ b/lib/src/main/java/dev/doglog/internal/writers/NetworkTablesWriter.java @@ -1,6 +1,5 @@ -package dev.doglog.internal.log_thread.writers; +package dev.doglog.internal.writers; -import dev.doglog.internal.writers.LogWriterLowLevel; import edu.wpi.first.networktables.BooleanArrayPublisher; import edu.wpi.first.networktables.BooleanPublisher; import edu.wpi.first.networktables.DoubleArrayPublisher; diff --git a/web/src/content/docs/getting-started/faq.md b/web/src/content/docs/getting-started/faq.md index 11b98a19..1ec484aa 100644 --- a/web/src/content/docs/getting-started/faq.md +++ b/web/src/content/docs/getting-started/faq.md @@ -15,7 +15,6 @@ Here's a quick breakdown of the differences between each library: | Logging pattern | [`DogLog.log()`](/getting-started/usage#logging) | [IO interfaces](https://docs.advantagekit.org/data-flow/recording-inputs/io-interfaces) and annotations | Annotations | | Use case | Simplest logging possible | [Replaying logs in simulation](https://docs.advantagekit.org/getting-started/what-is-advantagekit/) | Log every public or private field in a class | | Customizable log destinations | [Yes (NT and datalog)](/reference/configuring/#networktables-publishing) | [Yes (NT and datalog)](https://docs.advantagekit.org/getting-started/installation/existing-projects#robot-configuration) | No (NT always on, datalog can be toggled) | -| Multithreading | Fully configurable (can use main thread or a separate thread) | Required (always uses log processing thread) | No | | Tunable values | [Yes](/guides/tunable-values) | [Yes](https://docs.advantagekit.org/data-flow/recording-inputs/dashboard-inputs/) | No | | Unit metadata | [Yes](/getting-started/usage#logging-with-units) | [Yes](https://docs.advantagekit.org/data-flow/supported-types/#units) | No | | Supported language | Java | Java | Java | diff --git a/web/src/content/docs/guides/formatting-a-usb-drive.mdoc b/web/src/content/docs/guides/formatting-a-usb-drive.mdoc index 04be08b8..25e9af64 100644 --- a/web/src/content/docs/guides/formatting-a-usb-drive.mdoc +++ b/web/src/content/docs/guides/formatting-a-usb-drive.mdoc @@ -3,18 +3,14 @@ title: Formatting a USB drive description: Learn how to format a USB drive to use with DogLog. --- -While DogLog supports logging to the roboRIO's internal storage, using a USB drive is the preferred method for storing logs. +While DogLog supports logging to the controller's internal storage, using a USB drive is the preferred method for storing logs. Some benefits of using a USB drive for logging include: - Having an easy way to access logs when the robot is turned off -- Ensuring you always have enough storage for logs, without worrying about old ones being overwritten to make -- A safer way to store logs than on the roboRIO's storage - - On the roboRIO 1, using a USB drive for logs avoids bricking the internal flash storage - - Read more about this failure mode [here](/reference/warnings/unsafe_log_destination) - - On the roboRIO 2, the microSD card frequently comes loose during hard collisions, causing log writes to fail without a USB +- Ensuring you always have enough storage for logs, without worrying about old ones being overwritten -This guide will walk you through the steps of formatting a USB drive to get it ready for use with DogLog on a robot. +This guide will walk you through the steps of formatting a USB drive to get it ready for use with DogLog. ## Steps @@ -49,14 +45,14 @@ This guide will walk you through the steps of formatting a USB drive to get it r ![A screenshot of a File Explorer window, with the context menu for the USB drive opened, and the "Eject" option hovered](../../../assets/guides/flashing-a-usb-drive/windows/file-explorer-eject.png) -1. Insert the USB drive into one of the roboRIO's USB ports +1. Insert the USB drive into one of the USB ports on your robot controller The next time your robot code starts up, logs will automatically be saved to the USB drive. {% /steps %} {% /tabitem %} {% tabitem label="Large drives (more than 32GB)" %} -Due to a limitation in the built-in Windows formatter, USB drives larger than 32GB can't be formatted as FAT32, which is the only format supported by the roboRIO. +Due to a limitation in the built-in Windows formatter, USB drives larger than 32GB can't be formatted as FAT32, which is the format supported by FRC robot controllers. As a workaround, this guide uses [Rufus](https://rufus.ie/en/), a free and open-source app for formatting USB drives. {% steps %} @@ -97,7 +93,7 @@ As a workaround, this guide uses [Rufus](https://rufus.ie/en/), a free and open- ![A screenshot of a File Explorer window, with the context menu for the USB drive opened, and the "Eject" option hovered](../../../assets/guides/flashing-a-usb-drive/windows/file-explorer-eject.png) -1. Insert the USB drive into one of the roboRIO's USB ports +1. Insert the USB drive into one of the USB ports on your robot controller The next time your robot code starts up, logs will automatically be saved to the USB drive. {% /steps %} @@ -127,7 +123,7 @@ As a workaround, this guide uses [Rufus](https://rufus.ie/en/), a free and open- ![A screenshot from a Finder window, showing a USB drive under the "Locations" tab with the eject button highlighted](../../../assets/guides/flashing-a-usb-drive/mac/eject.png) -1. Insert the USB drive into one of the roboRIO's USB ports +1. Insert the USB drive into one of the USB ports on your robot controller The next time your robot code starts up, logs will automatically be saved to the USB drive. {% /steps %} diff --git a/web/src/content/docs/reference/Errors/max_queued_logs.md b/web/src/content/docs/reference/Errors/max_queued_logs.md deleted file mode 100644 index 5e22ca36..00000000 --- a/web/src/content/docs/reference/Errors/max_queued_logs.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: MAX_QUEUED_LOGS -description: Description and solution for the DogLog MAX_QUEUED_LOGS error. ---- - -## Description - -By default, DogLog uses a separate thread for handling log operations. -When that thread is enabled, each call to `DogLog#log()` is added to a queue to be processed by the log thread. -If too many logs are added to the queue before they can be processed, the queue becomes full and logs can't be added. - -If you disable the log thread with [`DogLogOptions#withUseLogThread(false)`](), the queue is not used and this error will not occur. - -## Solution - -To avoid this error, you can try the following: - -- Reduce the number of logs being added to the queue, especially in short bursts -- Increase the queue capacity in the configured DogLog options - - [Read more about how to configure this option here](/reference/configuring#log-entry-queue-capacity) - - [Relevant JavaDoc page for this option]() -- Process logs from the main thread directly, instead of queueing them, using [`DogLogOptions#withUseLogThread(false)`]() diff --git a/web/src/content/docs/reference/Errors/queue_resize_dropped_logs.md b/web/src/content/docs/reference/Errors/queue_resize_dropped_logs.md deleted file mode 100644 index 8836dc55..00000000 --- a/web/src/content/docs/reference/Errors/queue_resize_dropped_logs.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: QUEUE_RESIZE_DROPPED_LOGS -description: Description and solution for the DogLog QUEUE_RESIZE_DROPPED_LOGS error. ---- - -## Description - -By default, DogLog uses a separate thread for handling log operations. -When that thread is enabled, each call to `DogLog#log()` is added to a queue to be processed in the background. - -This error occurs when the queue capacity is reduced, and there are too many unprocessed logs to fit in the queue. -When this happens, logs are dropped, meaning they are lost and not processed. - -If you disable the log thread with [`DogLogOptions#withUseLogThread(false)`](), the queue is not used and this error will not occur. - -## Solution - -To avoid this error, you can try the following: - -- Resize the queue when there are less pending log entries in the queue -- Don't reduce the queue capacity so much diff --git a/web/src/content/docs/reference/Warnings/risky_queue_resize.md b/web/src/content/docs/reference/Warnings/risky_queue_resize.md deleted file mode 100644 index 6b02a679..00000000 --- a/web/src/content/docs/reference/Warnings/risky_queue_resize.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: RISKY_QUEUE_RESIZE -description: Description and solution for the DogLog RISKY_QUEUE_RESIZE warning. ---- - -## Description - -By default, DogLog uses a separate thread for handling log operations. -When that thread is enabled, each call to `DogLog#log()` is queued for asynchronous processing. -If the queue capacity is reduced, you are at risk of having log entries dropped. - -If you disable the log thread with [`DogLogOptions#withUseLogThread(false)`](), the queue is not used and this warning does not apply. - -This warning on its own is not a problem, but ignoring it may lead to other issues like [`QUEUE_RESIZE_DROPPED_LOGS`](/reference/errors/queue_resize_dropped_logs). diff --git a/web/src/content/docs/reference/Warnings/unsafe_log_destination.mdoc b/web/src/content/docs/reference/Warnings/unsafe_log_destination.mdoc deleted file mode 100644 index 521ee603..00000000 --- a/web/src/content/docs/reference/Warnings/unsafe_log_destination.mdoc +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: UNSAFE_LOG_DESTINATION -description: Description and solution for the DogLog UNSAFE_LOG_DESTINATION warning. ---- - -## Description - -DogLog uses WPILib's `DataLogManager` to manage writing logs to `.wpilog` files. -If a properly formatted USB drive is plugged into the roboRIO, `DataLogManager` will automatically store logs there. -Otherwise, logs will be stored on the roboRIO's storage. - -On a roboRIO 2, this means logs will be written to the microSD card. -This makes it impossible to easily access logs without having the robot powered on to download them, but other than that, is a valid way to store logs. - -On a roboRIO 1, however, this means logs will be written to the internal flash storage. -Flash memory like the one on the roboRIO 1 can only support a limited number of write cycles in its lifetime, before writes will fail. -Without a USB to use for logs, there is a risk of bricking the roboRIO from the increased write load caused by logging. - -This warning will be recorded when DogLog is being used on a roboRIO 1 without a properly formatted USB drive attached. - -## Solution - -Plugging in a properly formatted USB drive into the roboRIO will prevent this warning from being recorded the next time your robot code starts up. - -To learn more about how to format a USB drive, you can use this guide: - -{% linkcard title="USB drive formatting guide" href="/guides/formatting-a-usb-drive" /%} diff --git a/web/src/content/docs/reference/configuring.mdoc b/web/src/content/docs/reference/configuring.mdoc index 952db15e..2dcab20d 100644 --- a/web/src/content/docs/reference/configuring.mdoc +++ b/web/src/content/docs/reference/configuring.mdoc @@ -89,38 +89,6 @@ By default console capture is enabled. DogLog.setOptions(new DogLogOptions().withCaptureConsole(false)); ``` -### Log entry queue capacity - -The `logEntryQueueCapacity` option controls the maximum number of log entries that can be queued for processing by the log thread. -If the number of queued log entries exceeds this value, logs will be dropped (lost). - -Decreasing this value can reduce memory usage, but may result in logs being dropped ([`MAX_QUEUED_LOGS`](/reference/errors/max_queued_logs)) if the logger can't keep up with the rate of log entries. - -Increasing this value can reduce the likelihood of logs being dropped, but will increase memory usage. - -You can see the number of queued logs under the `Robot/DogLog/QueuedLogs` log key, to get a sense of how to tune this value. -When the log thread is disabled, queue metrics like `QueuedLogs` and `QueueRemainingCapacity` are set to `-1`, because entries are processed immediately. - -By default the queue is configured to support up to 1000 entries pending processing. - -```java -DogLog.setOptions(new DogLogOptions().withLogEntryQueueCapacity(1000)); -``` - -### Log processing thread - -The `useLogThread` option controls whether log entries are processed on a dedicated background thread or directly from the main robot thread. - -Leaving the log thread enabled (the default) can reduce CPU usage while your robot code is running, but will use extra memory to queue logs. -Disabling the thread removes that queue entirely, so every call to `DogLog.log()` is written immediately. - -```java -DogLog.setOptions(new DogLogOptions().withUseLogThread(false)); -``` - -Turning off the log thread can be useful if you want to minimize memory usage or avoid queue-related warnings. -If you're having issues with memory consumption or are seeing loop overruns, changing whether the log thread is on or off may help. - ### NetworkTables tunable values The `ntTunables` option controls whether NetworkTables will be used for [tunable values](/guides/tunable-values).