Class Logger


  • public class Logger
    extends Object
    This is a helper class that provides some convenience methods wrapped around the standard Logger interface. The class also makes sure that logger names of each Metro subsystem are consistent with each other.
    Author:
    Marek Potociar, Fabian Ritzmann
    • Constructor Detail

      • Logger

        protected Logger​(String systemLoggerName,
                         String componentName)
        Prevents creation of a new instance of this Logger unless used by a subclass.
        Parameters:
        systemLoggerName - system logger name
        componentName - component name
    • Method Detail

      • getLogger

        @NotNull
        public static Logger getLogger​(@NotNull
                                       Class<?> componentClass)

        The factory method returns preconfigured Logger wrapper for the class. Method calls getSystemLoggerName(java.lang.Class) to generate default logger name.

        Since there is no caching implemented, it is advised that the method is called only once per a class in order to initialize a final static logger variable, which is then used through the class to perform actual logging tasks.

        Parameters:
        componentClass - class of the component that will use the logger instance. Must not be null.
        Returns:
        logger instance preconfigured for use with the component
        Throws:
        NullPointerException - if the componentClass parameter is null.
      • getLogger

        @NotNull
        public static Logger getLogger​(@NotNull
                                       String customLoggerName,
                                       @NotNull
                                       Class<?> componentClass)
        The factory method returns preconfigured Logger wrapper for the class. Since there is no caching implemented, it is advised that the method is called only once per a class in order to initialize a final static logger variable, which is then used through the class to perform actual logging tasks. This method should be only used in a special cases when overriding of a default logger name derived from the package of the component class is needed. For all common use cases please use getLogger(java.lang.Class) method.
        Parameters:
        customLoggerName - custom name of the logger.
        componentClass - class of the component that will use the logger instance. Must not be null.
        Returns:
        logger instance preconfigured for use with the component
        Throws:
        NullPointerException - if the componentClass parameter is null.
        See Also:
        getLogger(java.lang.Class)
      • log

        public void log​(Level level,
                        String message)
      • finest

        public void finest​(String message)
      • finest

        public void finest​(String message,
                           Object[] params)
      • finer

        public void finer​(String message)
      • finer

        public void finer​(String message,
                          Object[] params)
      • fine

        public void fine​(String message)
      • info

        public void info​(String message)
      • info

        public void info​(String message,
                         Object[] params)
      • config

        public void config​(String message)
      • config

        public void config​(String message,
                           Object[] params)
      • warning

        public void warning​(String message)
      • warning

        public void warning​(String message,
                            Object[] params)
      • severe

        public void severe​(String message)
      • severe

        public void severe​(String message,
                           Object[] params)
      • isMethodCallLoggable

        public boolean isMethodCallLoggable()
      • isLoggable

        public boolean isLoggable​(Level level)
      • setLevel

        public void setLevel​(Level level)
      • entering

        public void entering()
      • entering

        public void entering​(Object... parameters)
      • exiting

        public void exiting()
      • exiting

        public void exiting​(Object result)
      • logSevereException

        public <T extends Throwable> T logSevereException​(T exception,
                                                          Throwable cause)
        Method logs exception's message as a SEVERE logging level message.

        If cause parameter is not null, it is logged as well and exception original cause is initialized with instance referenced by cause parameter.

        Type Parameters:
        T - type
        Parameters:
        exception - exception whose message should be logged. Must not be null.
        cause - initial cause of the exception that should be logged as well and set as exception's original cause. May be null.
        Returns:
        the same exception instance that was passed in as the exception parameter.
      • logSevereException

        public <T extends Throwable> T logSevereException​(T exception,
                                                          boolean logCause)
        Method logs exception's message as a SEVERE logging level message.

        If logCause parameter is true, exception's original cause is logged as well (if exists). This may be used in cases when exception's class provides constructor to initialize the original cause. In such case you do not need to use logSevereException(Throwable, Throwable) method version but you might still want to log the original cause as well.

        Type Parameters:
        T - type
        Parameters:
        exception - exception whose message should be logged. Must not be null.
        logCause - deterimnes whether initial cause of the exception should be logged as well
        Returns:
        the same exception instance that was passed in as the exception parameter.
      • logSevereException

        public <T extends Throwable> T logSevereException​(T exception)
        Type Parameters:
        T - type
        Parameters:
        exception - exception whose message should be logged. Must not be null.
        Returns:
        the same exception instance that was passed in as the exception parameter.
      • logException

        public <T extends Throwable> T logException​(T exception,
                                                    Throwable cause,
                                                    Level level)
        Method logs exception's message at the logging level specified by the level argument.

        If cause parameter is not null, it is logged as well and exception original cause is initialized with instance referenced by cause parameter.

        Type Parameters:
        T - type
        Parameters:
        exception - exception whose message should be logged. Must not be null.
        cause - initial cause of the exception that should be logged as well and set as exception's original cause. May be null.
        level - loging level which should be used for logging
        Returns:
        the same exception instance that was passed in as the exception parameter.
      • logException

        public <T extends Throwable> T logException​(T exception,
                                                    boolean logCause,
                                                    Level level)
        Method logs exception's message at the logging level specified by the level argument.

        If logCause parameter is true, exception's original cause is logged as well (if exists). This may be used in cases when exception's class provides constructor to initialize the original cause. In such case you do not need to use logException(exception, cause, level) method version but you might still want to log the original cause as well.

        Type Parameters:
        T - type
        Parameters:
        exception - exception whose message should be logged. Must not be null.
        logCause - deterimnes whether initial cause of the exception should be logged as well
        level - loging level which should be used for logging
        Returns:
        the same exception instance that was passed in as the exception parameter.
      • logException

        public <T extends Throwable> T logException​(T exception,
                                                    Level level)
        Type Parameters:
        T - type
        Parameters:
        exception - exception whose message should be logged. Must not be null.
        level - loging level which should be used for logging
        Returns:
        the same exception instance that was passed in as the exception parameter.