Class LogEntryFormatter

java.lang.Object
java.util.logging.Formatter
org.apache.juneau.microservice.resources.LogEntryFormatter

public class LogEntryFormatter extends Formatter
Log entry formatter.

Uses three simple parameter for configuring log entry formats:

  • dateFormat - A SimpleDateFormat string describing the format for dates.
  • format - A string with {...} replacement variables representing predefined fields.
  • useStackTraceHashes - A setting that causes duplicate stack traces to be replaced with 8-character hash strings.

This class converts the format strings into a regular expression that can be used to parse the resulting log file.

  • Constructor Details

    • LogEntryFormatter

      public LogEntryFormatter(String format, String dateFormat, boolean useStackTraceHashes)
      Create a new formatter.
      Parameters:
      format - The log entry format. e.g. "[{date} {level}] {msg}%n" The string can contain any of the following variables:
      1. "{date}" - The date, formatted per "Logging/dateFormat".
      2. "{class}" - The class name.
      3. "{method}" - The method name.
      4. "{logger}" - The logger name.
      5. "{level}" - The log level name.
      6. "{msg}" - The log message.
      7. "{threadid}" - The thread ID.
      8. "{exception}" - The localized exception message.
      dateFormat - The SimpleDateFormat format to use for dates. e.g. "yyyy.MM.dd hh:mm:ss".
      useStackTraceHashes - If true, only print unique stack traces once and then refer to them by a simple 8 character hash identifier.
  • Method Details

    • getLogEntryPattern

      Returns the regular expression pattern used for matching log entries.
      Returns:
      The regular expression pattern used for matching log entries.
    • getDateFormat

      Returns the DateFormat used for matching dates.
      Returns:
      The DateFormat used for matching dates.
    • getField

      public String getField(String fieldName, Matcher m)
      Given a matcher that has matched the pattern specified by getLogEntryPattern(), returns the field value from the match.
      Parameters:
      fieldName - The field name. Possible values are:
      • "date"
      • "class"
      • "method"
      • "logger"
      • "level"
      • "msg"
      • "threadid"
      • "exception"
      m - The matcher.
      Returns:
      The field value, or null if the specified field does not exist.
    • format

      public String format(LogRecord r)
      Specified by:
      format in class Formatter