bb.util.logging
Class FormatterFull

java.lang.Object
  extended by java.util.logging.Formatter
      extended by bb.util.logging.FormatterFull

public class FormatterFull
extends Formatter

Like XMLFormatter, this class uses almost all of the information in a LogRecord in its output and is ideal for a FileHandler to use. It differs in that it uses a plain text form, instead of xml, so that it is more human readable (e.g. by some operator pouring thru log files). See format for details.

The FormatterFull.Parser inner class may be used to parse LogRecords from text which was generated from LogRecords formatted by this class. For example, this could be used by a program to analyse log files.

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer

Nested Class Summary
static class FormatterFull.Parser
          Class which parses LogRecords from data generated by format.
static class FormatterFull.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private static String entrySeparator
           
private static String spacer
           
 
Constructor Summary
FormatterFull()
           
 
Method Summary
 String format(LogRecord record)
          Formats record into a String that looks like: -------------------------------------------------- level seq#sss date thread#ttt className.methodName [optional message, with any localization and param substitution applied] [optional Throwable; first line is its class name and message, followed by its stack trace] Notes: sss is record's sequence number, which uniquely identifies it among every LogRecord known by LogManager ttt is record's int thread ID value if the optional message is present, then localization and param substitution are perfomed by a call to formatMessage(record) a newline is always appended to the message if it is non-null, so the user need not add this This format was chosen for several reasons.
 
Methods inherited from class java.util.logging.Formatter
formatMessage, getHead, getTail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entrySeparator

private static final String entrySeparator
See Also:
Constant Field Values

spacer

private static final String spacer
See Also:
Constant Field Values
Constructor Detail

FormatterFull

public FormatterFull()
Method Detail

format

public String format(LogRecord record)
              throws IllegalArgumentException
Formats record into a String that looks like:

 --------------------------------------------------
 level    seq#sss    date    thread#ttt    className.methodName
 [optional message, with any localization and param substitution applied]
 [optional Throwable; first line is its class name and message, followed by its stack trace]
 

Notes:

  1. sss is record's sequence number, which uniquely identifies it among every LogRecord known by LogManager
  2. ttt is record's int thread ID value
  3. if the optional message is present, then localization and param substitution are perfomed by a call to formatMessage(record)
  4. a newline is always appended to the message if it is non-null, so the user need not add this

This format was chosen for several reasons. First, it contains all the useful information: every "get" method of record is used except for getLoggerName and getResourceBundleName. Second, it has a logical, top down order: all the metadata is in the top row, followed by the actual data (message and Throwable). Third, its compact form minimizes the number of lines. Fourth, the dashed separator visually delimits LogRecords, making it easier for a human reader to parse the logs

Specified by:
format in class Formatter
Parameters:
record - the LogRecord to be formatted; must not be null
Returns:
a String representation of record
Throws:
IllegalArgumentException - if record == null; if record's message, after formatting, contains entrySeparator