Class CustomFormatter

java.lang.Object
java.util.logging.Formatter
rma.util.logging.CustomFormatter
Direct Known Subclasses:
StackFilteringFormatter

public class CustomFormatter extends Formatter
A Formatter that may be customized in a logging.properties file. The syntax of the property rma.util.logging.CustomFormatter.format specifies the output. A newline will be appended to the string and the following special characters will be expanded (case sensitive):-
  • %m - message
  • %L - log level
  • %n - name of the logger
  • %t - a timestamp (in ISO-8601 "yyyy-MM-dd HH:mm:ss.SSS" format)
  • %M - source method name (if available, otherwise "?")
  • %c - source class name (if available, otherwise "?")
  • %C - source simple class name (if available, otherwise "?")
  • %T - thread ID
  • %E - (Filename.java:linenumber) Slow to generate Eclipse format
The default format is "%t %L: %E %m". Curly brace characters are not allowed. Based on http://javablog.co.uk/2008/07/12/logging-with-javautillogging/ %E Eclipse format was added with flag to avoid Stack trace generation if Eclipse format not used.
  • Field Details

  • Constructor Details

    • CustomFormatter

      public CustomFormatter()
  • Method Details

    • format

      public String format(LogRecord record)
      Specified by:
      format in class Formatter
    • formatMessage

      public StringBuffer formatMessage(LogRecord record, StringBuffer result)
      Localize and format the message string from a log record.

      The message string is first localized to a format string using the record's ResourceBundle. (If there is no ResourceBundle, or if the message key is not found, then the key is used as the format string.) The format String uses java.text style formatting.

      • If there are no parameters, no formatter is used.
      • Otherwise, if the string contains "{0" then java.text.MessageFormat is used to format the string.
      • Otherwise no formatting is performed.

      Parameters:
      record - the log record containing the raw message
      result - the StringBuffer where the message text is to be appended
      Returns:
      StringBuffer where the message text was appended
    • getThrowableMessage

      protected StringBuffer getThrowableMessage(LogRecord record, StringBuffer sb)
    • getEclipseFormat

      public StringBuffer getEclipseFormat(LogRecord logRecord, StringBuffer sb)
      Returns caller location information in eclipse format eg (Filename.java:23) WARNING Generating caller location information is slow. It's use should be avoided unless execution speed is not an issue.
      Parameters:
      sb -
      Returns:
      the eclipse format
    • appendEclipseFormat

      public static StringBuffer appendEclipseFormat(StackTraceElement element, StringBuffer sb)
      Appends the filename and line number to the provided StringBuffer. Chaining together the append calls was found (via testing) to be faster.
      Parameters:
      element -
      sb -
      Returns:
    • findCallingElement

      public static StackTraceElement findCallingElement(Throwable newThrowable, int depth)
    • getStackTraceDepth

      public static int getStackTraceDepth(Throwable newThrowable) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException
      Throws:
      InvocationTargetException
      IllegalAccessException
      IllegalArgumentException
    • getStackTraceElement

      public static StackTraceElement getStackTraceElement(Throwable newThrowable, int depth)
    • useReflection

      public static boolean useReflection()