Class ClientLogger


  • public class ClientLogger
    extends java.lang.Object
    This is a fluent logger helper class that wraps a pluggable Logger.

    This logger logs formattable messages that use {} as the placeholder. When a throwable is the last argument of the format varargs and the logger is enabled for verbose, the stack trace for the throwable is logged.

    Log level hierarchy

    1. Error
    2. Warning
    3. Info
    4. Verbose
    • Constructor Summary

      Constructors 
      Constructor Description
      ClientLogger​(java.lang.Class<?> clazz)
      Retrieves a logger for the passed class using the LoggerFactory.
      ClientLogger​(java.lang.String className)
      Retrieves a logger for the passed class name using the LoggerFactory.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canLogAtLevel​(LogLevel logLevel)
      Determines if the app or environment logger support logging at the given log level.
      void error​(java.lang.String message)
      Logs a message at error log level.
      void error​(java.lang.String format, java.lang.Object... args)
      Logs a formattable message that uses {} as the placeholder at error log level.
      void info​(java.lang.String message)
      Logs a message at info log level.
      void info​(java.lang.String format, java.lang.Object... args)
      Logs a formattable message that uses {} as the placeholder at informational log level.
      java.lang.RuntimeException logExceptionAsError​(java.lang.RuntimeException runtimeException)
      Logs the RuntimeException at the error level and returns it to be thrown.
      java.lang.RuntimeException logExceptionAsWarning​(java.lang.RuntimeException runtimeException)
      Logs the RuntimeException at the warning level and returns it to be thrown.
      <T extends java.lang.Throwable>
      T
      logThrowableAsError​(T throwable)
      Logs the Throwable at the error level and returns it to be thrown.
      <T extends java.lang.Throwable>
      T
      logThrowableAsWarning​(T throwable)
      Logs the Throwable at the warning level and returns it to be thrown.
      void verbose​(java.lang.String message)
      Logs a message at verbose log level.
      void verbose​(java.lang.String format, java.lang.Object... args)
      Logs a formattable message that uses {} as the placeholder at verbose log level.
      void warning​(java.lang.String message)
      Logs a message at warning log level.
      void warning​(java.lang.String format, java.lang.Object... args)
      Logs a formattable message that uses {} as the placeholder at warning log level.
      • Methods inherited from class java.lang.Object

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

      • ClientLogger

        public ClientLogger​(java.lang.Class<?> clazz)
        Retrieves a logger for the passed class using the LoggerFactory.
        Parameters:
        clazz - Class creating the logger.
      • ClientLogger

        public ClientLogger​(java.lang.String className)
        Retrieves a logger for the passed class name using the LoggerFactory.
        Parameters:
        className - Class name creating the logger.
        Throws:
        java.lang.RuntimeException - it is an error.
    • Method Detail

      • verbose

        public void verbose​(java.lang.String message)
        Logs a message at verbose log level.
        Parameters:
        message - The message to log.
      • verbose

        public void verbose​(java.lang.String format,
                            java.lang.Object... args)
        Logs a formattable message that uses {} as the placeholder at verbose log level.
        Parameters:
        format - The formattable message to log.
        args - Arguments for the message. If an exception is being logged, the last argument should be the Throwable.
      • info

        public void info​(java.lang.String message)
        Logs a message at info log level.
        Parameters:
        message - The message to log.
      • info

        public void info​(java.lang.String format,
                         java.lang.Object... args)
        Logs a formattable message that uses {} as the placeholder at informational log level.
        Parameters:
        format - The formattable message to log
        args - Arguments for the message. If an exception is being logged, the last argument should be the Throwable.
      • warning

        public void warning​(java.lang.String message)
        Logs a message at warning log level.
        Parameters:
        message - The message to log.
      • warning

        public void warning​(java.lang.String format,
                            java.lang.Object... args)
        Logs a formattable message that uses {} as the placeholder at warning log level.
        Parameters:
        format - The formattable message to log.
        args - Arguments for the message. If an exception is being logged, the last argument should be the Throwable.
      • error

        public void error​(java.lang.String message)
        Logs a message at error log level.
        Parameters:
        message - The message to log.
      • error

        public void error​(java.lang.String format,
                          java.lang.Object... args)
        Logs a formattable message that uses {} as the placeholder at error log level.
        Parameters:
        format - The formattable message to log.
        args - Arguments for the message. If an exception is being logged, the last argument should be the Throwable.
      • logExceptionAsWarning

        public java.lang.RuntimeException logExceptionAsWarning​(java.lang.RuntimeException runtimeException)
        Logs the RuntimeException at the warning level and returns it to be thrown.

        This API covers the cases where a runtime exception type needs to be thrown and logged. If a Throwable is being logged use logThrowableAsWarning(Throwable) instead.

        Parameters:
        runtimeException - RuntimeException to be logged and returned.
        Returns:
        The passed RuntimeException.
        Throws:
        java.lang.NullPointerException - If runtimeException is null.
      • logThrowableAsWarning

        public <T extends java.lang.Throwable> T logThrowableAsWarning​(T throwable)
        Logs the Throwable at the warning level and returns it to be thrown.

        This API covers the cases where a checked exception type needs to be thrown and logged. If a RuntimeException is being logged use logExceptionAsWarning(RuntimeException) instead.

        Type Parameters:
        T - Type of the Throwable being logged.
        Parameters:
        throwable - Throwable to be logged and returned.
        Returns:
        The passed Throwable.
        Throws:
        java.lang.NullPointerException - If throwable is null.
      • logExceptionAsError

        public java.lang.RuntimeException logExceptionAsError​(java.lang.RuntimeException runtimeException)
        Logs the RuntimeException at the error level and returns it to be thrown.

        This API covers the cases where a runtime exception type needs to be thrown and logged. If a Throwable is being logged use logThrowableAsError(Throwable) instead.

        Parameters:
        runtimeException - RuntimeException to be logged and returned.
        Returns:
        The passed RuntimeException.
        Throws:
        java.lang.NullPointerException - If runtimeException is null.
      • logThrowableAsError

        public <T extends java.lang.Throwable> T logThrowableAsError​(T throwable)
        Logs the Throwable at the error level and returns it to be thrown.

        This API covers the cases where a checked exception type needs to be thrown and logged. If a RuntimeException is being logged use logExceptionAsError(RuntimeException) instead.

        Type Parameters:
        T - Type of the Throwable being logged.
        Parameters:
        throwable - Throwable to be logged and returned.
        Returns:
        The passed Throwable.
        Throws:
        java.lang.NullPointerException - If throwable is null.
      • canLogAtLevel

        public boolean canLogAtLevel​(LogLevel logLevel)
        Determines if the app or environment logger support logging at the given log level.
        Parameters:
        logLevel - Logging level for the log message.
        Returns:
        Flag indicating if the environment and logger are configured to support logging at the given log level.