Class FallbackLogger

java.lang.Object
de.iip_ecosphere.platform.support.logging.FallbackLogger
All Implemented Interfaces:
Logger

public class FallbackLogger extends Object implements Logger
A fallback logger to sysout/syserr.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • FallbackLogger

      public FallbackLogger(String name)
      Creates an instance.
      Parameters:
      name - the name of the logger
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Logger
      Returns the name of the logger.
      Specified by:
      getName in interface Logger
      Returns:
      the name of the logger
    • setEmitter

      public boolean setEmitter(Logger.Emitter emitter)
      Description copied from interface: Logger
      Sets the emitter so that the output format can be changed programmatically. May not be supported by all loggers.
      Specified by:
      setEmitter in interface Logger
      Parameters:
      emitter - the emitter, shall be ignored if null
      Returns:
      true if accepted, false if ignored
    • setStreams

      public void setStreams(PrintStream out, PrintStream err)
      Sets the streams for logging.
      Parameters:
      out - the output stream (ignored if null)
      err - the error stream (ignored if null)
    • setLevel

      public boolean setLevel(LogLevel level)
      Description copied from interface: Logger
      Sets the log level.
      Specified by:
      setLevel in interface Logger
      Parameters:
      level - the new log level
      Returns:
      true if successful and changed, false if not changed or ignored
    • getLevel

      public LogLevel getLevel()
      Returns the log level.
      Specified by:
      getLevel in interface Logger
      Returns:
      the log level, may be null if not accessible/unknown
    • trace

      public void trace(String msg)
      Description copied from interface: Logger
      Log a message at the TRACE level.
      Specified by:
      trace in interface Logger
      Parameters:
      msg - the message string to be logged
    • trace

      public void trace(String format, Object arg)
      Description copied from interface: Logger
      Log a message at the TRACE level according to the specified format and argument.
      Specified by:
      trace in interface Logger
      Parameters:
      format - the format string
      arg - the argument
    • trace

      public void trace(String format, Object arg1, Object arg2)
      Description copied from interface: Logger
      Log a message at the TRACE level according to the specified format and arguments.
      Specified by:
      trace in interface Logger
      Parameters:
      format - the format string
      arg1 - the first argument
      arg2 - the second argument
    • trace

      public void trace(String format, Object... arguments)
      Description copied from interface: Logger
      Log a message at the TRACE level according to the specified format and arguments.
      Specified by:
      trace in interface Logger
      Parameters:
      format - the format string
      arguments - a list of 3 or more arguments
    • trace

      public void trace(String msg, Throwable th)
      Description copied from interface: Logger
      Log an exception (throwable) at the TRACE level with an accompanying message.
      Specified by:
      trace in interface Logger
      Parameters:
      msg - the message accompanying the exception
      th - the exception (throwable) to log
    • debug

      public void debug(String msg)
      Description copied from interface: Logger
      Log a message at the DEBUG level.
      Specified by:
      debug in interface Logger
      Parameters:
      msg - the message string to be logged
    • debug

      public void debug(String format, Object arg)
      Description copied from interface: Logger
      Log a message at the DEBUG level according to the specified format and argument.
      Specified by:
      debug in interface Logger
      Parameters:
      format - the format string
      arg - the argument
    • debug

      public void debug(String format, Object arg1, Object arg2)
      Description copied from interface: Logger
      Log a message at the DEBUG level according to the specified format and arguments.
      Specified by:
      debug in interface Logger
      Parameters:
      format - the format string
      arg1 - the first argument
      arg2 - the second argument
    • debug

      public void debug(String format, Object... arguments)
      Description copied from interface: Logger
      Log a message at the DEBUG level according to the specified format and arguments.
      Specified by:
      debug in interface Logger
      Parameters:
      format - the format string
      arguments - a list of 3 or more arguments
    • debug

      public void debug(String msg, Throwable th)
      Description copied from interface: Logger
      Log an exception (throwable) at the DEBUG level with an accompanying message.
      Specified by:
      debug in interface Logger
      Parameters:
      msg - the message accompanying the exception
      th - the exception (throwable) to log
    • info

      public void info(String msg)
      Description copied from interface: Logger
      Log a message at the INFO level.
      Specified by:
      info in interface Logger
      Parameters:
      msg - the message string to be logged
    • info

      public void info(String format, Object arg)
      Description copied from interface: Logger
      Log a message at the INFO level according to the specified format and argument.
      Specified by:
      info in interface Logger
      Parameters:
      format - the format string
      arg - the argument
    • info

      public void info(String format, Object arg1, Object arg2)
      Description copied from interface: Logger
      Log a message at the INFO level according to the specified format and arguments.
      Specified by:
      info in interface Logger
      Parameters:
      format - the format string
      arg1 - the first argument
      arg2 - the second argument
    • info

      public void info(String format, Object... arguments)
      Description copied from interface: Logger
      Log a message at the INFO level according to the specified format and arguments.
      Specified by:
      info in interface Logger
      Parameters:
      format - the format string
      arguments - a list of 3 or more arguments
    • info

      public void info(String msg, Throwable th)
      Description copied from interface: Logger
      Log an exception (throwable) at the INFO level with an accompanying message.
      Specified by:
      info in interface Logger
      Parameters:
      msg - the message accompanying the exception
      th - the exception (throwable) to log
    • warn

      public void warn(String msg)
      Description copied from interface: Logger
      Log a message at the WARN level.
      Specified by:
      warn in interface Logger
      Parameters:
      msg - the message string to be logged
    • warn

      public void warn(String format, Object arg)
      Description copied from interface: Logger
      Log a message at the WARN level according to the specified format and argument.
      Specified by:
      warn in interface Logger
      Parameters:
      format - the format string
      arg - the argument
    • warn

      public void warn(String format, Object arg1, Object arg2)
      Description copied from interface: Logger
      Log a message at the WARN level according to the specified format and arguments.
      Specified by:
      warn in interface Logger
      Parameters:
      format - the format string
      arg1 - the first argument
      arg2 - the second argument
    • warn

      public void warn(String format, Object... arguments)
      Description copied from interface: Logger
      Log a message at the WARN level according to the specified format and arguments.
      Specified by:
      warn in interface Logger
      Parameters:
      format - the format string
      arguments - a list of 3 or more arguments
    • warn

      public void warn(String msg, Throwable th)
      Description copied from interface: Logger
      Log an exception (throwable) at the WARN level with an accompanying message.
      Specified by:
      warn in interface Logger
      Parameters:
      msg - the message accompanying the exception
      th - the exception (throwable) to log
    • error

      public void error(String msg)
      Description copied from interface: Logger
      Log a message at the ERROR level.
      Specified by:
      error in interface Logger
      Parameters:
      msg - the message string to be logged
    • error

      public void error(String format, Object arg)
      Description copied from interface: Logger
      Log a message at the ERROR level according to the specified format and argument.
      Specified by:
      error in interface Logger
      Parameters:
      format - the format string
      arg - the argument
    • error

      public void error(String format, Object arg1, Object arg2)
      Description copied from interface: Logger
      Log a message at the ERROR level according to the specified format and arguments.
      Specified by:
      error in interface Logger
      Parameters:
      format - the format string
      arg1 - the first argument
      arg2 - the second argument
    • error

      public void error(String format, Object... arguments)
      Description copied from interface: Logger
      Log a message at the ERROR level according to the specified format and arguments.
      Specified by:
      error in interface Logger
      Parameters:
      format - the format string
      arguments - a list of 3 or more arguments
    • error

      public void error(String msg, Throwable th)
      Description copied from interface: Logger
      Log an exception (throwable) at the ERROR level with an accompanying message.
      Specified by:
      error in interface Logger
      Parameters:
      msg - the message accompanying the exception
      th - the exception (throwable) to log
    • isEnabled

      private boolean isEnabled(LogLevel level)
      Returns whether the given level is enabled.
      Parameters:
      level - the target logging level
      Returns:
      true for enabled, false else
    • emit

      private void emit(LogLevel level, String msg, Throwable th, PrintStream out)
      Emits the given message msg with no argument, possibly with the given throwable th.
      Parameters:
      level - the target loglevel
      msg - the message, logged is it is, prefixed with logger name, logger level and time
      th - optional throwable to be logged, may be null
      out - the target output stream
    • log

      private void log(LogLevel level, String msg, Throwable th, PrintStream out)
      Logs the given message msg with no argument, possibly with the given throwable th if level is enabled.
      Parameters:
      level - the target loglevel
      msg - the message, logged is it is, prefixed with logger name, logger level and time
      th - optional throwable to be logged, may be null
      out - the target output stream
    • abbreviate

      public static String abbreviate(String name)
      Abbreviates a qualified class name.
      Parameters:
      name - the name
      Returns:
      the abbreviated name
    • toString

      private String toString(Object arg)
      Turns an argument object to a string value.
      Parameters:
      arg - the argument, may be null
      Returns:
      the string value
    • logArgs

      private void logArgs(LogLevel level, String format, PrintStream out, Object arg)
      Logs with one argument if level is enabled.
      Parameters:
      level - the target loglevel
      format - the logging format, placeholders as "{}"
      out - the target output stream
      arg - the argument
    • logArgs

      private void logArgs(LogLevel level, String format, PrintStream out, Object arg1, Object arg2)
      Logs with two arguments if level is enabled.
      Parameters:
      level - the target loglevel
      format - the logging format, placeholders as "{}"
      out - the target output stream
      arg1 - the first argument
      arg2 - the second argument
    • logArgs

      private void logArgs(LogLevel level, String format, PrintStream out, Object[] args)
      Logs with arbitrary arguments if level is enabled.
      Parameters:
      level - the target loglevel
      format - the logging format, placeholders as "{}"
      out - the target output stream
      args - the arguments
    • replaceOnce

      private static String replaceOnce(String text, String searchString, String replacement)
      Replaces searchString once in text by replacement.
      Parameters:
      text - the text to search for and to replace within
      searchString - the string to search for
      replacement - the replacement string
      Returns:
      text with the first occurrence of searchString replaced