Class LogStorage

java.lang.Object
frc.spectrumLib.telemetry.LogStorage

public final class LogStorage extends Object
Where the robot's logs go on SystemCore, and keeping them from filling its storage.

A full internal disk is a SystemCore failure other teams have hit at events: a robot that rebooted mid-match with an empty log, another that lost control with 50 MB left, deploys that deleted the robot program (wpilibsuite/SystemcoreTesting #210, #211, #156). Every log goes to internal storage when no USB stick is in, and nothing else ever deletes them; the bench unit had 408 MB of them after two days. So:

  • chooseFolder() waits briefly for a USB stick to mount before settling on internal storage: the robot program can start before /U is mounted (SystemcoreTesting #341).
  • cleanUpAtBoot() deletes the oldest logs before this boot's log exists.
  • start() checks free space off the main thread and trims the internal folder if the disk runs short; periodic() turns the result into alerts and log values on the main thread.

SystemCore can boot with its clock behind older logs, so this boot's log can sort oldest. A file is never deleted if it appeared after cleanUpAtBoot() or was modified within ACTIVE_WINDOW_MILLIS.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Below this much free space the storage alert goes red.
    static final long
    Free space cleanup keeps on the disk holding the logs.
    static final long
    Most internal storage this program's logs may use.
    static final String
     
    static final String
     
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    The folder to log to: the USB stick if one is (or within USB_WAIT_SECONDS becomes) mounted, else internal storage.
    static long[]
    cleanUp(File dir, long capBytes, long freeFloorBytes, int keepNewest)
     
    static long[]
    cleanUp(File dir, long capBytes, long freeFloorBytes, int keepNewest, Set<String> protectedNames)
    Deletes the oldest log files in dir until they total at most capBytes and the disk has at least freeFloorBytes free.
    static void
    Cleans the internal log folder and remembers which logs exist, so later ones are protected.
    static String
    The folder chosen at boot.
    static void
    Alerts and log values from the last background check.
    static void
    Reports the boot cleanup and starts the background free-space check.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • chooseFolder

      public static String chooseFolder()
      The folder to log to: the USB stick if one is (or within USB_WAIT_SECONDS becomes) mounted, else internal storage. Blocks at most that long, and only when /U exists.
      Returns:
      the log folder, created if needed
    • cleanUp

      public static long[] cleanUp(File dir, long capBytes, long freeFloorBytes, int keepNewest, Set<String> protectedNames)
      Deletes the oldest log files in dir until they total at most capBytes and the disk has at least freeFloorBytes free.
      Parameters:
      dir - the log folder
      capBytes - most the logs may total
      freeFloorBytes - free space to leave on the disk
      keepNewest - how many of the newest logs are kept
      protectedNames - files never deleted
      Returns:
      {count deleted, bytes deleted}
    • cleanUp

      public static long[] cleanUp(File dir, long capBytes, long freeFloorBytes, int keepNewest)
    • cleanUpAtBoot

      public static void cleanUpAtBoot()
      Cleans the internal log folder and remembers which logs exist, so later ones are protected. Call before Logger.start().
    • start

      public static void start()
      Reports the boot cleanup and starts the background free-space check. Call after Logger.start().
    • periodic

      public static void periodic()
      Alerts and log values from the last background check. Call once per loop; cheap.
    • folder

      public static String folder()
      The folder chosen at boot.