Package jmri.util

Class LoggingUtil

java.lang.Object
jmri.util.LoggingUtil

public class LoggingUtil extends Object
Basic utilities for logging special messages.
  • Field Details

  • Constructor Details

  • Method Details

    • warnOnce

      public static boolean warnOnce(@Nonnull org.slf4j.Logger logger, @Nonnull String msg, Object... args)
      Emit a particular WARNING-level message just once.

      Goal is to be lightweight and fast; this will only be used in a few places, and only those should appear in data structure.

      Parameters:
      logger - the source of the warning
      msg - warning message
      args - message arguments
      Returns:
      true if the log was emitted this time
    • infoOnce

      public static boolean infoOnce(@Nonnull org.slf4j.Logger logger, @Nonnull String msg, Object... args)
      Emit a particular INFO-level message just once.

      Goal is to be lightweight and fast; this will only be used in a few places, and only those should appear in data structure.

      Parameters:
      logger - the source of the warning
      msg - info message
      args - message arguments
      Returns:
      true if the log was emitted this time
    • deprecationWarning

      public static void deprecationWarning(@Nonnull org.slf4j.Logger logger, @Nonnull String methodName)
      Warn that a deprecated method has been invoked.

      Can also be used to warn of some deprecated condition, i.e. obsolete-format input data.

      The logging is turned off by default during testing to simplify updating tests when warnings are added.

      Parameters:
      logger - The Logger to warn.
      methodName - method name.
    • shortenStacktrace

      @Nonnull public static <T extends Throwable> T shortenStacktrace(@Nonnull T t)
      Shorten a stack trace to start with the first JMRI method.

      When logged, the stack trace will be more focused.

      Type Parameters:
      T - the type of Throwable
      Parameters:
      t - the Throwable containing the stack trace to truncate
      Returns:
      t with truncated stack trace
    • shortenStacktrace

      @Nonnull public static <T extends Throwable> T shortenStacktrace(@Nonnull T t, int len)
      Shorten a stack trace to a fixed length.

      When logged, the stack trace will be more focused.

      Type Parameters:
      T - the type of Throwable
      Parameters:
      t - the Throwable containing the stack trace to truncate
      len - length of stack trace to retain
      Returns:
      t with truncated stack trace