Package jmri.util

Class LoggingUtil


  • public class LoggingUtil
    extends java.lang.Object
    Basic utilities for logging special messages.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.util.Map<org.slf4j.Logger,​java.util.Set<java.lang.String>> infodOnce  
      protected static boolean logDeprecations  
      protected static java.util.Map<org.slf4j.Logger,​java.util.Set<java.lang.String>> warnedOnce  
    • Constructor Summary

      Constructors 
      Constructor Description
      LoggingUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void deprecationWarning​(org.slf4j.Logger logger, java.lang.String methodName)
      Warn that a deprecated method has been invoked.
      static boolean infoOnce​(org.slf4j.Logger logger, java.lang.String msg, java.lang.Object... args)
      Emit a particular INFO-level message just once.
      static <T extends java.lang.Throwable>
      T
      shortenStacktrace​(T t)
      Shorten a stack trace to start with the first JMRI method.
      static <T extends java.lang.Throwable>
      T
      shortenStacktrace​(T t, int len)
      Shorten a stack trace to a fixed length.
      static boolean warnOnce​(org.slf4j.Logger logger, java.lang.String msg, java.lang.Object... args)
      Emit a particular WARNING-level message just once.
      • Methods inherited from class java.lang.Object

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

      • warnedOnce

        protected static java.util.Map<org.slf4j.Logger,​java.util.Set<java.lang.String>> warnedOnce
      • infodOnce

        protected static java.util.Map<org.slf4j.Logger,​java.util.Set<java.lang.String>> infodOnce
    • Method Detail

      • warnOnce

        public static boolean warnOnce​(@Nonnull
                                       org.slf4j.Logger logger,
                                       @Nonnull
                                       java.lang.String msg,
                                       java.lang.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
                                       java.lang.String msg,
                                       java.lang.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
                                              java.lang.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 java.lang.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 java.lang.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