Package de.gebit.integrity.runner.logging

## Class DefaultFixtureLogger

- java.lang.Object
- - de.gebit.integrity.runner.logging.DefaultFixtureLogger

- All Implemented Interfaces:
    `FixtureLogger`, `AggregatingFixtureLogger`

      public class DefaultFixtureLogger
      extends Object
      implements AggregatingFixtureLogger

  The default implementation of a `FixtureLogger` usually used in Integrity.
  Author:
    Rene Schneider - initial API and implementation

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected ConsoleOutputInterceptor` | `consoleOutputInterceptor` | The console interceptor.
    `protected static char` | `ESCAPE_CHAR` | The escape character, which can be used to actually put the `PARAM_STR` pattern into a log message without it being replaced.
    `protected static String` | `FIXTURE_LOG_CONSOLE_PREFIX` | The prefix for fixture log lines that are being printed on the console.
    `static String` | `LOG_TRACE_PROPERTY` | Set this system property to turn on verbose logging of fixture log output.
    `protected List<LogLine>` | `loggedLines` | All logged lines are collected here.
    `protected static char` | `PARAM_START` | Parameter placeholders are started with this char.
    `protected static char` | `PARAM_STOP` | Parameter placeholders end with this char.
    `protected static String` | `PARAM_STR` | This string is the parameter placeholder.
    `protected List<LogLine>` | `resultLoggedLines` | The unmodifiable collection returned to callers is cached here, in case multiple callers need the same one.
    `protected FixtureLogLevel` | `thresholdLevel` | Only log messages that equal this level or are coarser than it will be logged.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultFixtureLogger()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected void` | `appendParameter​(StringBuilder aBuffer, Object aParam)` | Appends the given parameter (which can be an array or a single object).
    `protected void` | `appendSimpleObjectParameter​(StringBuilder aBuffer, Object aParam)` | Appends the given parameter, which at this point must be a single object.
    `void` | `clearLines()` | Clears any lines currently stored in the logger.
    `void` | `debug​(String aMessage, Object... someParameters)` | Log the specified message at `FixtureLogLevel.DEBUG` level.
    `void` | `error​(String aMessage, Object... someParameters)` | Log the specified message at `FixtureLogLevel.ERROR` level.
    `List<LogLine>` | `getLines()` | Returns the currently aggregated log lines, but does NOT clear the buffer.
    `void` | `info​(String aMessage, Object... someParameters)` | Log the specified message at `FixtureLogLevel.INFO` level.
    `void` | `log​(FixtureLogLevel aLevel, String aMessage, Object... someParameters)` | Log the specified message at the specified log level.
    `protected void` | `printLogLine​(LogLine aLine)` | Prints the log line on the console.
    `protected String` | `replaceParameterPlaceholders​(String aMessage, Object... someParameters)` | Replaces all parameter placeholders in the given message with the given parameters.
    `void` | `setThresholdLevel​(FixtureLogLevel aThresholdLevel)` | Sets the threshold level interactively at runtime.
    `protected List<LogLine>` | `stackTraceToLogLines​(Throwable anException, FixtureLogLevel aLevel)` | Formats a stack trace into a list of log lines.
    `void` | `trace​(String aMessage, Object... someParameters)` | Log the specified message at `FixtureLogLevel.TRACE` level.
    `void` | `warn​(String aMessage, Object... someParameters)` | Log the specified message at `FixtureLogLevel.WARNING` level.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### loggedLines

          protected List<LogLine> loggedLines

      All logged lines are collected here.

    - #### resultLoggedLines

          protected List<LogLine> resultLoggedLines

      The unmodifiable collection returned to callers is cached here, in case multiple callers need the same one.

    - #### thresholdLevel

          protected FixtureLogLevel thresholdLevel

      Only log messages that equal this level or are coarser than it will be logged.

    - #### LOG_TRACE_PROPERTY

          public static final String LOG_TRACE_PROPERTY

      Set this system property to turn on verbose logging of fixture log output. Log output on level `FixtureLogLevel.TRACE` will not be actually logged otherwise, since the default level is `FixtureLogLevel.DEBUG`.
      See Also:
        Constant Field Values

    - #### consoleOutputInterceptor

          @Inject
          protected ConsoleOutputInterceptor consoleOutputInterceptor

      The console interceptor.

    - #### FIXTURE_LOG_CONSOLE_PREFIX

          protected static final String FIXTURE_LOG_CONSOLE_PREFIX

      The prefix for fixture log lines that are being printed on the console.
      See Also:
        Constant Field Values

    - #### PARAM_START

          protected static final char PARAM_START

      Parameter placeholders are started with this char.
      See Also:
        Constant Field Values

    - #### PARAM_STOP

          protected static final char PARAM_STOP

      Parameter placeholders end with this char.
      See Also:
        Constant Field Values

    - #### PARAM_STR

          protected static final String PARAM_STR

      This string is the parameter placeholder.
      See Also:
        Constant Field Values

    - #### ESCAPE_CHAR

          protected static final char ESCAPE_CHAR

      The escape character, which can be used to actually put the `PARAM_STR` pattern into a log message without it being replaced. It can itself be escaped by prepending it with itself.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DefaultFixtureLogger

          public DefaultFixtureLogger()

  - ### Method Detail

    - #### setThresholdLevel

          public void setThresholdLevel​(FixtureLogLevel aThresholdLevel)

      Sets the threshold level interactively at runtime. Only log messages that equal this level or are coarser than it will be logged.
      Parameters:
        `aThresholdLevel` - the level to compare with

    - #### getLines

          public List<LogLine> getLines()

      Description copied from interface: `AggregatingFixtureLogger`
      Returns the currently aggregated log lines, but does NOT clear the buffer. This method guarantees to return a finalized collection that will not be modified anymore by the aggregator.
      Specified by:
        `getLines` in interface `AggregatingFixtureLogger`
      Returns:
        the logged lines

    - #### clearLines

          public void clearLines()

      Description copied from interface: `AggregatingFixtureLogger`
      Clears any lines currently stored in the logger.
      Specified by:
        `clearLines` in interface `AggregatingFixtureLogger`

    - #### log

          public void log​(FixtureLogLevel aLevel,
                          String aMessage,
                          Object... someParameters)

      Description copied from interface: `FixtureLogger`
      Log the specified message at the specified log level. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted to `String`s by calling toString().

      An exception is the last parameter: if it is a `Throwable`, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of the `Throwable` is logged as part of the log message.

      Specified by:
        `log` in interface `FixtureLogger`
      Parameters:
        `aLevel` - the log level
        `aMessage` - the message to log (possibly with placeholders)
        `someParameters` - parameters to insert into placeholders, optionally a `Throwable` at the end of the list

    - #### printLogLine

          protected void printLogLine​(LogLine aLine)

      Prints the log line on the console.
      Parameters:
        `aLine` -

    - #### stackTraceToLogLines

          protected List<LogLine> stackTraceToLogLines​(Throwable anException,
                                                       FixtureLogLevel aLevel)

      Formats a stack trace into a list of log lines. This is more convenient for fixture logging purposes, even though it breaks with some common conventions regarding stack trace logging.
      Parameters:
        `anException` - the exception from which to get the stack trace
      Returns:
        the stack trace as a list of `LogLine`s

    - #### error

          public void error​(String aMessage,
                            Object... someParameters)

      Description copied from interface: `FixtureLogger`
      Log the specified message at `FixtureLogLevel.ERROR` level. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted to `String`s by calling toString().

      An exception is the last parameter: if it is a `Throwable`, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of the `Throwable` is logged as part of the log message.

      Specified by:
        `error` in interface `FixtureLogger`
      Parameters:
        `aMessage` - the message to log (possibly with placeholders)
        `someParameters` - parameters to insert into placeholders, optionally a `Throwable` at the end of the list

    - #### warn

          public void warn​(String aMessage,
                           Object... someParameters)

      Description copied from interface: `FixtureLogger`
      Log the specified message at `FixtureLogLevel.WARNING` level. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted to `String`s by calling toString().

      An exception is the last parameter: if it is a `Throwable`, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of the `Throwable` is logged as part of the log message.

      Specified by:
        `warn` in interface `FixtureLogger`
      Parameters:
        `aMessage` - the message to log (possibly with placeholders)
        `someParameters` - parameters to insert into placeholders, optionally a `Throwable` at the end of the list

    - #### info

          public void info​(String aMessage,
                           Object... someParameters)

      Description copied from interface: `FixtureLogger`
      Log the specified message at `FixtureLogLevel.INFO` level. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted to `String`s by calling toString().

      An exception is the last parameter: if it is a `Throwable`, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of the `Throwable` is logged as part of the log message.

      Specified by:
        `info` in interface `FixtureLogger`
      Parameters:
        `aMessage` - the message to log (possibly with placeholders)
        `someParameters` - parameters to insert into placeholders, optionally a `Throwable` at the end of the list

    - #### debug

          public void debug​(String aMessage,
                            Object... someParameters)

      Description copied from interface: `FixtureLogger`
      Log the specified message at `FixtureLogLevel.DEBUG` level. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted to `String`s by calling toString().

      An exception is the last parameter: if it is a `Throwable`, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of the `Throwable` is logged as part of the log message.

      Specified by:
        `debug` in interface `FixtureLogger`
      Parameters:
        `aMessage` - the message to log (possibly with placeholders)
        `someParameters` - parameters to insert into placeholders, optionally a `Throwable` at the end of the list

    - #### trace

          public void trace​(String aMessage,
                            Object... someParameters)

      Description copied from interface: `FixtureLogger`
      Log the specified message at `FixtureLogLevel.TRACE` level. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted to `String`s by calling toString().

      An exception is the last parameter: if it is a `Throwable`, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of the `Throwable` is logged as part of the log message.

      Specified by:
        `trace` in interface `FixtureLogger`
      Parameters:
        `aMessage` - the message to log (possibly with placeholders)
        `someParameters` - parameters to insert into placeholders, optionally a `Throwable` at the end of the list

    - #### replaceParameterPlaceholders

          protected String replaceParameterPlaceholders​(String aMessage,
                                                        Object... someParameters)

      Replaces all parameter placeholders in the given message with the given parameters.
      Parameters:
        `aMessage` - the message to process
        `someParameters` - the parameters to insert
      Returns:
        the finished message

    - #### appendParameter

          protected void appendParameter​(StringBuilder aBuffer,
                                         Object aParam)

      Appends the given parameter (which can be an array or a single object).
      Parameters:
        `aBuffer` - the buffer to append to
        `aParam` - the parameter

    - #### appendSimpleObjectParameter

          protected void appendSimpleObjectParameter​(StringBuilder aBuffer,
                                                     Object aParam)

      Appends the given parameter, which at this point must be a single object.
      Parameters:
        `aBuffer` - the buffer to append to
        `aParam` - the parameter