JavaGantt 2011.1 API

eu.beesoft.gaia.log.java
Class ConfigurableFormatter

java.lang.Object
  extended by java.util.logging.Formatter
      extended by eu.beesoft.gaia.log.java.ConfigurableFormatter

public class ConfigurableFormatter
extends java.util.logging.Formatter

Supports formatting for Java logging system. This formatter can be configured via method setFormat(String). Configuration string describes how to format log data. Here are supported commands:

t - date/time in millis
Y - year
M - month
D - day
h - hour
m - minute
s - second
u - millis
L - level
T - thread
P - parameter (thread bound) object
C - qualified class name
c - short class name
G - message

You can combine more of them in the configuration string. Each command must start with % character, then follows (optional) width in characters with possible '-' (minus) sign before it to force rigth-side alignment, and ends with command letter. Here is as an example the default configuration string:

                %D.%M.%Y %h:%m:%s.%u [%5L] %T %-45C | %G
 

Note the P command: it formats a first parameter from java.util.logging.LogRecord obtained with its method getParameters(). The JavaLog uses this parameter to store a thread bound identifier, if it was set via LogFactory.setThreadBoundIdentifier(String) method. This command is useful in a server environment, it is more understandable to write lo log for example a client / user name, than just simple thread name.


Constructor Summary
ConfigurableFormatter()
          Creates a new instance of configurable formatter.
 
Method Summary
 java.lang.String format(java.util.logging.LogRecord record)
          Overrides parent's format() method to apply this instance formatting
 java.lang.String getFormat()
          Returns currently used format.
 void setFormat(java.lang.String format)
          Sets a new format.
 
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
 

Constructor Detail

ConfigurableFormatter

public ConfigurableFormatter()
Creates a new instance of configurable formatter. Sets format to: %D.%M.%Y %h:%m:%s.%u [%5L] %T %-45C | %G

Method Detail

getFormat

public java.lang.String getFormat()
Returns currently used format.

Returns:
current format

setFormat

public void setFormat(java.lang.String format)
Sets a new format. See this class description about enabled formats. param format - a format to set


format

public java.lang.String format(java.util.logging.LogRecord record)
Overrides parent's format() method to apply this instance formatting

Specified by:
format in class java.util.logging.Formatter
Parameters:
record - - source data for formatting
Returns:
formatted text to log

JavaGantt 2011.1 API