net.directj.jlogger
Class PatternFormatter

java.lang.Object
  |
  +--net.directj.jlogger.PatternFormatter
All Implemented Interfaces:
Formatter
Direct Known Subclasses:
DefaultFormatter

public class PatternFormatter
extends java.lang.Object
implements Formatter

This is a pattern formatter, that allow you to create you're own format. There is four paramaters that will be replace by the corresponding logging information: $type, $message, $time and $name. For example, the DefaultFormatter use the pattern: "[$name] $type - $message #$time", and it will produce for example "INFO - log1 information #20 dc. 2002 03:16:22".

Version:
0.1.7
Author:
CARTAPANIS Alexandre <earendil@jprolog.net>

Field Summary
private  java.lang.String pattern
          The pattern.
 
Constructor Summary
PatternFormatter(java.lang.String _pattern)
          The default constructor, with a specified pattern.
 
Method Summary
 boolean equals(java.lang.Object _obj)
          Indicates whether some other object is "equal to" this one.
 java.lang.String getFooter()
          Returns the footer information of the formatter.
 java.lang.String getHeader()
          Returns the header information of the formatter.
 int hashCode()
          Returns a hash code value for the object.
static java.lang.String replace(java.lang.String _str, java.lang.String _repl, java.lang.String _with, int _max)
          Replace a string with another string inside a larger string, for the first _max values of the search string.
 java.lang.String transform(LogRecord _record)
          Transforms the given logging info with a special format.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pattern

private java.lang.String pattern
The pattern.

Constructor Detail

PatternFormatter

public PatternFormatter(java.lang.String _pattern)
The default constructor, with a specified pattern.

Parameters:
_pattern - The pattern.
Method Detail

transform

public java.lang.String transform(LogRecord _record)
Transforms the given logging info with a special format. In fact, it just replace the pattern string "$type", "$message", "$name" and "$type" by corresponding information.

Specified by:
transform in interface Formatter
Parameters:
_record - The log record, where logging information are stored.
Returns:
String - The String that has been created using the given logging information.

replace

public static java.lang.String replace(java.lang.String _str,
                                       java.lang.String _repl,
                                       java.lang.String _with,
                                       int _max)
Replace a string with another string inside a larger string, for the first _max values of the search string. A null reference is passed to this method is a no-op.

Parameters:
_str - The String to search and replace in.
_repl - String to search for.
_with - String to replace with.
_max - The maximum number of values to replace, or -1 if no maximum.
Returns:
String - The text with any replacements processed.

getHeader

public java.lang.String getHeader()
Returns the header information of the formatter. Usefull for file that need header, like xml or html. Other formatter will return an empty string. As a developper you don't have to take care of this method, it is automatically called by the LogManager that is in charge of the formatter.

Specified by:
getHeader in interface Formatter
Returns:
String - The formatter header.

getFooter

public java.lang.String getFooter()
Returns the footer information of the formatter. Usefull for file that need header, like xml or html. Other formatter will return an empty string. As a developper you don't have to take care of this method, it is automatically called by the LogManager that is in charge of the formatter.

Specified by:
getFooter in interface Formatter
Returns:
String - The formatter footer.

equals

public boolean equals(java.lang.Object _obj)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
_obj - The reference object with which to compare.
Returns:
boolean - True if this object is the same as the obj argument; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

Overrides:
hashCode in class java.lang.Object
Returns:
int - A hash code value for this object.


Copyright 2002 CARTAPANIS Alexandre
This page was last updated on May 10 2003