ch.javasoft.util.logging
Class LogFormatter

java.lang.Object
  extended by java.util.logging.Formatter
      extended by ch.javasoft.util.logging.LogFormatter

public class LogFormatter
extends Formatter

The LogFormatter formats log statements with the help of a MessageFormat. The format string can be configured in the log configuration (ch.javasoft.util.logging.LogFormatter.format property).

The following arguments are passed to the message format:

Note that all strings (all arguments but 0 and 5) have fixed length, meaning that the strings are either truncated or filled with spaces.

For instance, the default format produces log statements like this:

 2004-10-13  22:18:50.932  main        JavaLogger      INFO     mymessage\n
 

Others might prefere the more compact plain format:

 mymessage\n
 


Nested Class Summary
static class LogFormatter.LogParameter
          Constants for interplay with LogFragmenter
 
Field Summary
static MessageFormat FORMAT_DEFAULT
          Default log format, a sample log line looks like this:
static MessageFormat FORMAT_PLAIN
          Plain log format, a sample log line looks like this:
 
Constructor Summary
LogFormatter()
          Constructor using the default format.
LogFormatter(Format format)
           
 
Method Summary
 String format(LogRecord record)
          Formats the record as described in the class comments.
 MessageFormat getDefaultFormat()
          Returns the default format.
protected  MessageFormat getFormatFromProperties()
          Read the logger format from the properties file, a log config property composed of this class's name and a '.format' suffix.
 
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

FORMAT_DEFAULT

public static final MessageFormat FORMAT_DEFAULT
Default log format, a sample log line looks like this:
 2004-10-13  22:18:50.932  main        JavaLogger      INFO     mymessage\n
 
To configure this format, set the ch.javasoft.util.logging.LogFormatter.format logging config property to
 {0,date,yyyy-MM-dd}  {0,time,HH:mm:ss.SSS}  {1}  {2}  {3}  | {4}{5}
 


FORMAT_PLAIN

public static final MessageFormat FORMAT_PLAIN
Plain log format, a sample log line looks like this:
 mymessage\n
 
To configure this format, set the ch.javasoft.util.logging.LogFormatter.format logging config property to
 {4}{5}
 

Constructor Detail

LogFormatter

public LogFormatter()
Constructor using the default format.


LogFormatter

public LogFormatter(Format format)
Method Detail

getFormatFromProperties

protected MessageFormat getFormatFromProperties()
Read the logger format from the properties file, a log config property composed of this class's name and a '.format' suffix.


getDefaultFormat

public final MessageFormat getDefaultFormat()
Returns the default format. The default format is read from the logger properties file (see getFormatFromProperties()), if this is not possible, for instance since no property exists of due to an invalid format expression, FORMAT_DEFAULT is used instead.


format

public String format(LogRecord record)
Formats the record as described in the class comments.

Specified by:
format in class Formatter