Class Logger

java.lang.Object
frc.robot.shared.logging.Logger

public class Logger extends Object
Logger is a utility class for logging messages with different levels of severity. It supports verbose, debug, info, warning, and error messages. The output is color-coded for better readability in the console and automatically includes the class name to help diagnose where the log originated. AdvantageKit is the preferred telemetry path; SmartDashboard helpers remain for operator-critical values only.

The recordVerboseOutput family of methods gates on both FMS attachment and the per-instance verbose flag. Verbose output is suppressed when the robot is connected to the FMS or when the owning subsystem has verbose disabled in its configuration. Use recordOutput for data that must always be logged for match replay.

For robot mode detection, FMS state, and Driver Station reporting, see RobotEnvironment.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Logger(String className, BooleanSupplier verboseSupplier)
    Creates a logger scoped to the provided class name.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Dismisses both the error and warning dashboard alerts.
    void
    debug(String message)
    Logs a debug message to the console if verbose output is enabled.
    void
    error(String message)
    Logs an error message to the standard error console and activates a persistent dashboard Alert.
    static <T> Logger
    Returns an instance of Logger for the specified class
    static <T> Logger
    getInstance(Class<T> c, boolean verbose)
    Returns an instance of Logger for the specified class with a fixed verbosity setting.
    static <T> Logger
    getInstance(Class<T> c, BooleanSupplier verboseSupplier)
    Returns an instance of Logger for the specified class with a dynamic verbosity supplier.
    static Logger
    getInstance(String className)
    Returns an instance of Logger for the specified name
    static Logger
    getInstance(String className, boolean verbose)
    Returns an instance of Logger for the specified name with a fixed verbosity setting.
    static Logger
    getInstance(String className, BooleanSupplier verboseSupplier)
    Returns an instance of Logger for the specified name with a dynamic verbosity supplier.
    void
    info(String message)
    Logs an informational message to the console.
    void
    processInputs(String key, org.littletonrobotics.junction.inputs.LoggableInputs inputs)
    Records an auto-logged input snapshot with the logger prefix applied.
    void
    recordOutput(String key, boolean value)
    Records a boolean to AdvantageKit using the class name as a prefix.
    void
    recordOutput(String key, double value)
    Records a numeric value to AdvantageKit using the class name as a prefix.
    void
    recordOutput(String key, double[] values)
    Records an array of numeric values to AdvantageKit using the class name as a prefix.
    void
    recordOutput(String key, String value)
    Records a string value to AdvantageKit using the class name as a prefix.
    <T extends edu.wpi.first.util.struct.StructSerializable>
    void
    recordOutput(String key, T value)
    Records a struct-serializable value to AdvantageKit using the class name as a prefix.
    <T extends edu.wpi.first.util.struct.StructSerializable>
    void
    recordOutput(String key, T... value)
    Records an array of struct-serializable values to AdvantageKit using the class name as a prefix.
    <T extends edu.wpi.first.util.struct.StructSerializable>
    void
    recordOutput(String key, T[][] value)
    Records a 2D array of struct-serializable values to AdvantageKit using the class name as a prefix.
    void
    recordVerboseOutput(String key, boolean value)
    Records a boolean to AdvantageKit only when not attached to the FMS and verbose is enabled.
    void
    recordVerboseOutput(String key, double value)
    Records a numeric value to AdvantageKit only when not attached to the FMS and verbose is enabled.
    void
    recordVerboseOutput(String key, double[] values)
    Records an array of numeric values to AdvantageKit only when not attached to the FMS and verbose is enabled.
    void
    Records a string value to AdvantageKit only when not attached to the FMS and verbose is enabled.
    <T extends edu.wpi.first.util.struct.StructSerializable>
    void
    recordVerboseOutput(String key, T value)
    Records a struct-serializable value to AdvantageKit only when not attached to the FMS and verbose is enabled.
    <T extends edu.wpi.first.util.struct.StructSerializable>
    void
    recordVerboseOutput(String key, T... value)
    Records an array of struct-serializable values to AdvantageKit only when not attached to the FMS and verbose is enabled.
    <T extends edu.wpi.first.util.struct.StructSerializable>
    void
    recordVerboseOutput(String key, T[][] value)
    Records a 2D array of struct-serializable values to AdvantageKit only when not attached to the FMS and verbose is enabled.
    void
    verbose(String message)
    Logs a verbose message to the console if verbose output is enabled.
    void
    warning(String message)
    Logs a warning message to the console and activates a persistent dashboard Alert.

    Methods inherited from class java.lang.Object

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

    • Logger

      protected Logger(String className, BooleanSupplier verboseSupplier)
      Creates a logger scoped to the provided class name.

      Two persistent Alert instances are created using the class name as the alert group so dashboard alerts are organized per-subsystem. Alerts remain active until explicitly cleared via clearAlerts().

      Parameters:
      className - name to prefix all log messages with
      verboseSupplier - supplier evaluated each cycle to determine whether verbose output is enabled
  • Method Details

    • getInstance

      public static <T> Logger getInstance(Class<T> c)
      Returns an instance of Logger for the specified class
      Type Parameters:
      T - the type of the class for which the Logger instance is being created
      Parameters:
      c - the Class object for which the Logger instance is being created
      Returns:
      a new Logger instance for the specified class with the given verbosity setting
    • getInstance

      public static <T> Logger getInstance(Class<T> c, boolean verbose)
      Returns an instance of Logger for the specified class with a fixed verbosity setting.
      Type Parameters:
      T - the type of the class for which the Logger instance is being created
      Parameters:
      c - the Class object for which the Logger instance is being created
      verbose - the verbosity setting for the logger
      Returns:
      a new Logger instance for the specified class with the given verbosity setting
    • getInstance

      public static <T> Logger getInstance(Class<T> c, BooleanSupplier verboseSupplier)
      Returns an instance of Logger for the specified class with a dynamic verbosity supplier.

      The supplier is evaluated each time the logger checks verbosity, allowing live toggling from dashboards without calling setVerbose.

      Type Parameters:
      T - the type of the class for which the Logger instance is being created
      Parameters:
      c - the Class object for which the Logger instance is being created
      verboseSupplier - supplier that returns true when verbose output should be enabled
      Returns:
      a new Logger instance for the specified class with the given verbosity supplier
    • getInstance

      public static Logger getInstance(String className)
      Returns an instance of Logger for the specified name
      Parameters:
      className - the name to scope the logger instance to
      Returns:
      a new Logger instance for the specified class with the given verbosity setting
    • getInstance

      public static Logger getInstance(String className, boolean verbose)
      Returns an instance of Logger for the specified name with a fixed verbosity setting.
      Parameters:
      className - the name to scope the logger instance to
      verbose - the verbosity setting for the logger
      Returns:
      a new Logger instance for the specified class with the given verbosity setting
    • getInstance

      public static Logger getInstance(String className, BooleanSupplier verboseSupplier)
      Returns an instance of Logger for the specified name with a dynamic verbosity supplier.

      The supplier is evaluated each time the logger checks verbosity, allowing live toggling from dashboards without calling setVerbose.

      Parameters:
      className - the name to scope the logger instance to
      verboseSupplier - supplier that returns true when verbose output should be enabled
      Returns:
      a new Logger instance for the specified class with the given verbosity supplier
    • verbose

      public void verbose(String message)
      Logs a verbose message to the console if verbose output is enabled. The message is prefixed with "VERBOSE:" and the class name, and is displayed in gray color.
      Parameters:
      message - The message to be logged.
    • debug

      public void debug(String message)
      Logs a debug message to the console if verbose output is enabled. The message is prefixed with "DEBUG:" and the class name, and is displayed in white color.
      Parameters:
      message - The debug message to be logged.
    • info

      public void info(String message)
      Logs an informational message to the console. The message is prefixed with "INFO:" and the class name, and is displayed in white color.
      Parameters:
      message - The informational message to be logged.
    • warning

      public void warning(String message)
      Logs a warning message to the console and activates a persistent dashboard Alert.

      The alert remains visible on supported dashboards until dismissed via clearAlerts(). Each call replaces the previous warning text, so only the most recent warning is displayed.

      Parameters:
      message - The warning message to be logged.
    • error

      public void error(String message)
      Logs an error message to the standard error console and activates a persistent dashboard Alert.

      The alert remains visible on supported dashboards until dismissed via clearAlerts(). Each call replaces the previous error text, so only the most recent error is displayed.

      Parameters:
      message - The error message to be logged.
    • clearAlerts

      public void clearAlerts()
      Dismisses both the error and warning dashboard alerts.

      Call this when a previously reported condition has recovered so stale alerts do not remain visible to operators. Safe to call even if no alerts are currently active.

    • recordOutput

      public void recordOutput(String key, boolean value)
      Records a boolean to AdvantageKit using the class name as a prefix. Prefer this for telemetry instead of SmartDashboard to reduce NetworkTables noise.
      Parameters:
      key - telemetry key suffix
      value - value to record
    • recordOutput

      public void recordOutput(String key, double value)
      Records a numeric value to AdvantageKit using the class name as a prefix. Prefer this for telemetry instead of SmartDashboard to reduce NetworkTables noise.
      Parameters:
      key - telemetry key suffix
      value - value to record
    • recordOutput

      public void recordOutput(String key, double[] values)
      Records an array of numeric values to AdvantageKit using the class name as a prefix.
      Parameters:
      key - telemetry key suffix
      values - values to record
    • recordOutput

      public void recordOutput(String key, String value)
      Records a string value to AdvantageKit using the class name as a prefix.
      Parameters:
      key - telemetry key suffix
      value - string value to record
    • recordOutput

      public <T extends edu.wpi.first.util.struct.StructSerializable> void recordOutput(String key, T value)
      Records a struct-serializable value to AdvantageKit using the class name as a prefix.

      Use this for WPILib types that implement StructSerializable (poses, rotations, chassis speeds, module states, etc.).

      Type Parameters:
      T - value type that supports struct serialization
      Parameters:
      key - telemetry key suffix
      value - struct-serializable value to record
    • recordOutput

      public <T extends edu.wpi.first.util.struct.StructSerializable> void recordOutput(String key, T... value)
      Records an array of struct-serializable values to AdvantageKit using the class name as a prefix.

      This matches AdvantageKit's struct array logging for types like module states or pose lists.

      Type Parameters:
      T - value type that supports struct serialization
      Parameters:
      key - telemetry key suffix
      value - struct-serializable values to record
    • recordOutput

      public <T extends edu.wpi.first.util.struct.StructSerializable> void recordOutput(String key, T[][] value)
      Records a 2D array of struct-serializable values to AdvantageKit using the class name as a prefix.
      Type Parameters:
      T - value type that supports struct serialization
      Parameters:
      key - telemetry key suffix
      value - struct-serializable values to record
    • processInputs

      public void processInputs(String key, org.littletonrobotics.junction.inputs.LoggableInputs inputs)
      Records an auto-logged input snapshot with the logger prefix applied.
      Parameters:
      key - input key suffix for AdvantageKit
      inputs - auto-logged inputs bundle to record
    • recordVerboseOutput

      public void recordVerboseOutput(String key, String value)
      Records a string value to AdvantageKit only when not attached to the FMS and verbose is enabled.
      Parameters:
      key - telemetry key suffix
      value - string value to record
    • recordVerboseOutput

      public void recordVerboseOutput(String key, boolean value)
      Records a boolean to AdvantageKit only when not attached to the FMS and verbose is enabled.
      Parameters:
      key - telemetry key suffix
      value - value to record
    • recordVerboseOutput

      public void recordVerboseOutput(String key, double value)
      Records a numeric value to AdvantageKit only when not attached to the FMS and verbose is enabled.
      Parameters:
      key - telemetry key suffix
      value - value to record
    • recordVerboseOutput

      public void recordVerboseOutput(String key, double[] values)
      Records an array of numeric values to AdvantageKit only when not attached to the FMS and verbose is enabled.
      Parameters:
      key - telemetry key suffix
      values - values to record
    • recordVerboseOutput

      public <T extends edu.wpi.first.util.struct.StructSerializable> void recordVerboseOutput(String key, T value)
      Records a struct-serializable value to AdvantageKit only when not attached to the FMS and verbose is enabled.
      Type Parameters:
      T - value type that supports struct serialization
      Parameters:
      key - telemetry key suffix
      value - struct-serializable value to record
    • recordVerboseOutput

      public <T extends edu.wpi.first.util.struct.StructSerializable> void recordVerboseOutput(String key, T... value)
      Records an array of struct-serializable values to AdvantageKit only when not attached to the FMS and verbose is enabled.
      Type Parameters:
      T - value type that supports struct serialization
      Parameters:
      key - telemetry key suffix
      value - struct-serializable values to record
    • recordVerboseOutput

      public <T extends edu.wpi.first.util.struct.StructSerializable> void recordVerboseOutput(String key, T[][] value)
      Records a 2D array of struct-serializable values to AdvantageKit only when not attached to the FMS and verbose is enabled.
      Type Parameters:
      T - value type that supports struct serialization
      Parameters:
      key - telemetry key suffix
      value - struct-serializable values to record