Package com.gengoai

Class LogUtils


  • public final class LogUtils
    extends Object
    Utilities for working with java.util.Logger.
    • Field Detail

      • FORMATTER

        public static final Formatter FORMATTER
        Instance of the MangoLogFormatter to share amongst Handlers.
      • LOG_FILTER

        public static final Filter LOG_FILTER
      • ROOT

        public static final Logger ROOT
        The root logger
    • Method Detail

      • addFileHandler

        public static void addFileHandler​(String basename)
                                   throws IOException
        Adds a file handler that writes to the location specified in com.gengoai.logging.dir or if not set USER_HOME/logs/. The filenames are in the form of basename%g where %g is the rotated file number. Max file size is 100MB and 50 files will be used.
        Parameters:
        basename - the basename
        Throws:
        IOException - the io exception
      • addHandler

        public static void addHandler​(Handler handler)
        Adds a handler to the root.
        Parameters:
        handler - the handler to add
      • getGlobalLogger

        public static Logger getGlobalLogger()
        Gets the global Logger
        Returns:
        The global logger
      • getLogger

        public static Logger getLogger​(@NonNull
                                       @NonNull Class<?> clazz)
        Gets a logger for the given class..
        Parameters:
        clazz - the class whose name will become the logger name
        Returns:
        the logger
      • getRootLogger

        public static Logger getRootLogger()
        Gets the root logger.
        Returns:
        the root logger
      • log

        public static void log​(@NonNull
                               @NonNull Logger logger,
                               @NonNull
                               @NonNull Level level,
                               String message,
                               Object... params)
        Logs a message at a given level.
        Parameters:
        logger - the logger
        level - The level to log the message at.
        message - The message accompanying the log
        params - The arguments for the message.
      • log

        public static void log​(@NonNull
                               @NonNull Logger logger,
                               @NonNull
                               @NonNull Level level,
                               @NonNull
                               @NonNull Throwable throwable)
        Logs the given throwable at a given level.
        Parameters:
        logger - the logger
        level - The level to log the message at.
        throwable - The throwable for the message.
      • log

        public static void log​(@NonNull
                               @NonNull Logger logger,
                               @NonNull
                               @NonNull Level level,
                               String message,
                               @NonNull
                               @NonNull Throwable throwable)
        Logs a message at a given level.
        Parameters:
        logger - the logger
        level - The level to log the message at.
        message - The message accompanying the log
        throwable - The throwable for the message.
      • logConfig

        public static void logConfig​(@NonNull
                                     @NonNull Logger logger,
                                     String message,
                                     Object... params)
        Logs a message at Level.CONFIG.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        params - The arguments for the message.
      • logConfig

        public static void logConfig​(@NonNull
                                     @NonNull Logger logger,
                                     String message,
                                     @NonNull
                                     @NonNull Throwable throwable)
        Logs the given throwable at Level.CONFIG.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        throwable - The throwable to log.
      • logConfig

        public static void logConfig​(@NonNull
                                     @NonNull Logger logger,
                                     @NonNull
                                     @NonNull Throwable throwable)
        Logs the given throwable at Level.CONFIG.
        Parameters:
        logger - the logger
        throwable - The throwable to log.
      • logFine

        public static void logFine​(@NonNull
                                   @NonNull Logger logger,
                                   String message,
                                   Object... params)
        Logs a message at Level.FINE.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        params - The arguments for the message.
      • logFine

        public static void logFine​(@NonNull
                                   @NonNull Logger logger,
                                   String message,
                                   @NonNull
                                   @NonNull Throwable throwable)
        Logs the given throwable at Level.FINE.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        throwable - The throwable to log.
      • logFine

        public static void logFine​(@NonNull
                                   @NonNull Logger logger,
                                   @NonNull
                                   @NonNull Throwable throwable)
        Logs the given throwable at Level.FINE.
        Parameters:
        logger - the logger
        throwable - The throwable to log.
      • logFiner

        public static void logFiner​(@NonNull
                                    @NonNull Logger logger,
                                    String message,
                                    Object... params)
        Logs a message at Level.FINER.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        params - The arguments for the message.
      • logFiner

        public static void logFiner​(@NonNull
                                    @NonNull Logger logger,
                                    String message,
                                    @NonNull
                                    @NonNull Throwable throwable)
        Logs the given throwable at Level.FINER.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        throwable - The throwable to log.
      • logFiner

        public static void logFiner​(@NonNull
                                    @NonNull Logger logger,
                                    @NonNull
                                    @NonNull Throwable throwable)
        Logs the given throwable at Level.FINER.
        Parameters:
        logger - the logger
        throwable - The throwable to log.
      • logFinest

        public static void logFinest​(@NonNull
                                     @NonNull Logger logger,
                                     String message,
                                     Object... params)
        Logs a message at Level.FINEST.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        params - The arguments for the message.
      • logFinest

        public static void logFinest​(@NonNull
                                     @NonNull Logger logger,
                                     String message,
                                     @NonNull
                                     @NonNull Throwable throwable)
        Logs the given throwable at Level.FINEST.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        throwable - The throwable to log.
      • logFinest

        public static void logFinest​(@NonNull
                                     @NonNull Logger logger,
                                     @NonNull
                                     @NonNull Throwable throwable)
        Logs the given throwable at Level.FINEST.
        Parameters:
        logger - the logger
        throwable - The throwable to log.
      • logInfo

        public static void logInfo​(@NonNull
                                   @NonNull Logger logger,
                                   String message,
                                   Object... params)
        Logs a message at Level.INFO.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        params - The arguments for the message.
      • logInfo

        public static void logInfo​(@NonNull
                                   @NonNull Logger logger,
                                   String message,
                                   @NonNull
                                   @NonNull Throwable throwable)
        Logs the given throwable at Level.INFO.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        throwable - The throwable to log.
      • logInfo

        public static void logInfo​(@NonNull
                                   @NonNull Logger logger,
                                   @NonNull
                                   @NonNull Throwable throwable)
        Logs the given throwable at Level.INFO.
        Parameters:
        logger - the logger
        throwable - The throwable to log.
      • logSevere

        public static void logSevere​(@NonNull
                                     @NonNull Logger logger,
                                     String message,
                                     Object... params)
        Logs a message at Level.SEVERE.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        params - The arguments for the message.
      • logSevere

        public static void logSevere​(@NonNull
                                     @NonNull Logger logger,
                                     String message,
                                     @NonNull
                                     @NonNull Throwable throwable)
        Logs the given throwable at Level.SEVERE.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        throwable - The throwable to log.
      • logSevere

        public static void logSevere​(@NonNull
                                     @NonNull Logger logger,
                                     @NonNull
                                     @NonNull Throwable throwable)
        Logs the given throwable at Level.SEVERE.
        Parameters:
        logger - the logger
        throwable - The throwable to log.
      • logWarning

        public static void logWarning​(@NonNull
                                      @NonNull Logger logger,
                                      String message,
                                      Object... params)
        Logs a message at Level.WARNING.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        params - The arguments for the message.
      • logWarning

        public static void logWarning​(@NonNull
                                      @NonNull Logger logger,
                                      String message,
                                      @NonNull
                                      @NonNull Throwable throwable)
        Logs the given throwable at Level.WARNING.
        Parameters:
        logger - the logger
        message - The message accompanying the log
        throwable - The throwable to log.
      • logWarning

        public static void logWarning​(@NonNull
                                      @NonNull Logger logger,
                                      @NonNull
                                      @NonNull Throwable throwable)
        Logs the given throwable at Level.WARNING.
        Parameters:
        logger - the logger
        throwable - The throwable to log.
      • setLevel

        public static void setLevel​(String logger,
                                    Level level)
        Sets the level of a logger
        Parameters:
        logger - The name of the logger to set the level for.
        level - The level to set the logger at