Skip to content

Using ILogSource

Renato Dell'Osso edited this page Feb 26, 2024 · 7 revisions

ILogSource is an interface you will use to organize logging and console operations in the robot code. If you want to log something in your code you will first need to ensure that the ILogSource is being implemented in the class. To do this you will need to put "implements ILogSource" at the end of the class declaration. For Example:

public class VisionSubsystem extends SubsystemBase implements ILogSource
{
}

Once this is done, You will now have access to all ILogSource methods to organize your logging.

There are ten methods implemented in your class. These methods make use of Level variables. The level variable has nine states:

  • All used when all messages should be logged.
  • OFF used when logging needs to be turned off. In order of severity:
  1. SEVERE used for serious failures or problems.
  2. WARNING used for indicating potential problems.
  3. INFO used for informational logging. This level will by default always show, no matter the source.
  4. CONFIG used for configuration logging.
  5. FINE used for basic tracing information. This level is for logs we want when testing a specific class, but do not always want to see.
  6. FINER used for fairly detailed tracing logs.
  7. FINEST used for the most detailed tracing logs, such as logging in periodic..

These levels are accessed through the level enumerator that should also be implemented. An example of this follows:

Level.FINE;
//or
Level.WARNING;

setLogFilterLevel(Level LevelOfMessage)
Takes one Logger level input shown above. Results in the level input or higher are logged and anything lower is ignored. For example in the following code:

setLogFilterLevel(Level.CONFIG);

This call results in all log messages that are lower in severity than CONFIG being ignored and dismissed. In this case, the levels that would be ignored are any that are the levels FINE, FINER, or FINEST. In addition to this, you can use the Levels ALL or OFF to turn all messages on or off.

log(Level levelOfMessage, String Message)
takes two inputs the level of the message being sent and the string message. Note that ALL and OFF CANNOT be used as a message severity and can only be used for the filter level. An example of the use of this function include:

Log(Level.SEVERE, "Severe message");
//or
Log(Level.INFO, "Informational message");

log + Level to use()
The remaining eight methods include a log with a specific level following for less ambiguous code. The name of the method will be "log" plus the level of the message capitalized. Examples of these messages are:

logFine("Fine message");
//also...
logFiner("Finer message");
logFinest("Finest message");

and so on for all level types except for OFF and ALL.

logException(Exception e)
When you have an exception object (from a try/catch block for example), use this method. It will log at log severe, but add a stack trace.

logException(String msg)
Creates a new Exception object with the specified message and then passes it to logException(Exception e).

Clone this wiki locally