net.sf.microlog.format
Class PatternFormatter

java.lang.Object
  extended by net.sf.microlog.format.PatternFormatter
All Implemented Interfaces:
Formatter

public class PatternFormatter
extends java.lang.Object
implements Formatter

This class is the equivalent to the PatternLayout found in Log4j. As far as possible all conversions should be available.

  Q: How do I setup the PatternFormatter in my microlog.properties file?
 
  A: You use the microlog.formatter.PatternFormatter.pattern property to set the pattern for the PatternFormatter.
 
  Example:
  # Set the pattern for the PatternFormatter
  microlog.formatter.PatternFormatter.pattern=%r %c %m %T
 
  This would print the relative logging time, the name of the Logger, the logged message and the Throwable object (if not null).
 
  The available pattern conversions are:
  %c : prints the name of the Logger
  %d : prints the date (absolute time)
  %m : prints the logged message
  %P : prints the priority, i.e. Level of the message.
  %r : prints the relative time of the logging. (The first logging is done at time 0.)
  %t : prints the thread name.
  %T : prints the Throwable object.
  %% : prints the '%' sign.
 

Since:
0.6
Author:
Johan Karlsson (johan.karlsson@jayway.se)

Field Summary
static char CATEGORY_CONVERSION_CHAR
           
static char DATE_CONVERSION_CHAR
           
static java.lang.String DEFAULT_CONVERSION_PATTERN
          This is the default pattern that is used for the PatternFormatter.
static char MESSAGE_CONVERSION_CHAR
           
static java.lang.String PATTERN_STRING
           
static char PERCENT_CONVERSION_CHAR
           
static char PRIORITY_CONVERSION_CHAR
           
static char RELATIVE_TIME_CONVERSION_CHAR
           
static char THREAD_CONVERSION_CHAR
           
static char THROWABLE_CONVERSION_CHAR
           
 
Constructor Summary
PatternFormatter()
          Create a PatternFormatter with the default pattern.
 
Method Summary
 void configure(PropertiesGetter properties)
          Configure the appender.
 java.lang.String format(java.lang.String name, long time, Level level, java.lang.Object message, java.lang.Throwable t)
          Format the input parameters.
 java.lang.String getPattern()
          Get the pattern that is when formatting.
 void setPattern(java.lang.String pattern)
          Set the pattern that is when formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONVERSION_PATTERN

public static final java.lang.String DEFAULT_CONVERSION_PATTERN
This is the default pattern that is used for the PatternFormatter. Developer notice: If you change the pattern, please test that the pattern works as expected. Otherwise it is possible that the default (no argument) constructor do not work as expected.

See Also:
Constant Field Values

PATTERN_STRING

public static final java.lang.String PATTERN_STRING
See Also:
Constant Field Values

CATEGORY_CONVERSION_CHAR

public static final char CATEGORY_CONVERSION_CHAR
See Also:
Constant Field Values

DATE_CONVERSION_CHAR

public static final char DATE_CONVERSION_CHAR
See Also:
Constant Field Values

MESSAGE_CONVERSION_CHAR

public static final char MESSAGE_CONVERSION_CHAR
See Also:
Constant Field Values

PRIORITY_CONVERSION_CHAR

public static final char PRIORITY_CONVERSION_CHAR
See Also:
Constant Field Values

RELATIVE_TIME_CONVERSION_CHAR

public static final char RELATIVE_TIME_CONVERSION_CHAR
See Also:
Constant Field Values

THREAD_CONVERSION_CHAR

public static final char THREAD_CONVERSION_CHAR
See Also:
Constant Field Values

THROWABLE_CONVERSION_CHAR

public static final char THROWABLE_CONVERSION_CHAR
See Also:
Constant Field Values

PERCENT_CONVERSION_CHAR

public static final char PERCENT_CONVERSION_CHAR
See Also:
Constant Field Values
Constructor Detail

PatternFormatter

public PatternFormatter()
Create a PatternFormatter with the default pattern.

Method Detail

format

public java.lang.String format(java.lang.String name,
                               long time,
                               Level level,
                               java.lang.Object message,
                               java.lang.Throwable t)
Format the input parameters.

Specified by:
format in interface Formatter
Parameters:
name - the name of the logger.
time - the time since the first logging has done (in milliseconds).
level - the logging level
message - the message
t - the exception.
Returns:
a String that is not null.
See Also:
Formatter.format(String, long, net.sf.microlog.Level, java.lang.Object, java.lang.Throwable)

configure

public void configure(PropertiesGetter properties)
               throws java.lang.IllegalArgumentException
Description copied from interface: Formatter
Configure the appender.

Specified by:
configure in interface Formatter
Parameters:
properties - Properties to configure with
Throws:
java.lang.IllegalArgumentException
See Also:
Formatter.configure(net.sf.microlog.util.PropertiesGetter)

getPattern

public java.lang.String getPattern()
Get the pattern that is when formatting.

Returns:
the pattern

setPattern

public void setPattern(java.lang.String pattern)
                throws java.lang.IllegalArgumentException
Set the pattern that is when formatting.

Parameters:
pattern - the pattern to set
Throws:
java.lang.IllegalArgumentException - if the pattern is null.


Copyright © 2009 SourceForge.net Microlog. All Rights Reserved.