Class LogFormatter

java.lang.Object
java.util.logging.Formatter
org.rapidcontext.util.LogFormatter

public class LogFormatter extends Formatter
A java.util.logging formatter with more output options. Adds to the default simple formatter by indenting multiple line entries, shortening stack traces, and removing the "org.rapidcontext" prefix for class names.

Configured by the following properties:

  • org.rapidcontext.logging.format -- same format parameters and options as java.util.logging.SimpleFormatter.format
  • org.rapidcontext.logging.format.indent -- indentation prefix for subsequent log lines (default is 4 spaces)
Version:
1.0
  • Field Details

    • DEFAULT_FORMAT

      protected static final String DEFAULT_FORMAT
      Default logging format.
      See Also:
    • FORMAT

      protected static final String FORMAT
      The log output format. Configured via the logging property "org.rapidcontext.logging.format". Uses same available formats and parameters as the java.util.logging.SimpleFormatter.format
    • INDENT

      protected static final String INDENT
      The indentation prefix for subsequent log lines. Configured via the logging property "org.rapidcontext.logging.format.indent". Default is 4 spaces.
  • Constructor Details

    • LogFormatter

      public LogFormatter()
      Creates a new log formatter instance.
  • Method Details

    • format

      public String format(LogRecord entry)
      Formats the specified log record for output.
      Specified by:
      format in class Formatter
      Parameters:
      entry - the log record to format
      Returns:
      the formatted log record
    • getSource

      protected String getSource(LogRecord entry)
      Returns the source class and method for a log record.
      Parameters:
      entry - the log record to use
      Returns:
      the source class and method, or the logger name if not set
    • getStackTrace

      protected String getStackTrace(LogRecord entry)
      Returns the stack trace from a log record.
      Parameters:
      entry - the log record to use
      Returns:
      the formatted stack trace, or an empty string if not set
    • indentFollowing

      protected String indentFollowing(String log)
      Returns an indented log output string.
      Parameters:
      log - the log output string
      Returns:
      the indented version of the log output