org.x4juli.global.components
Class AbstractFormatter

java.lang.Object
  extended byjava.util.logging.Formatter
      extended byorg.x4juli.global.components.AbstractFormatter
All Implemented Interfaces:
Component, ExtendedFormatter, Formatter, OptionHandler
Direct Known Subclasses:
HTMLFormatter, PatternFormatter, SimpleFormatter

public abstract class AbstractFormatter
extends java.util.logging.Formatter
implements Component, OptionHandler, ExtendedFormatter

AbstractFormatter is for ease of development. It must extend java.util.logging.Formatter and be a Component with the attributes of a BaseComponent. The code of BaseComponent is copied here therefor.

Since:
0.5
Author:
Boris Unckel

Field Summary
private  int errorCount
           
protected  boolean ignoresThrowable
          Formatter ignores throwables in output or not.
private  ExtendedLogger logger
           
protected  java.util.logging.LogManager manager
          LogManager for easy access.
protected  ObjectStore repository
          Store for this component.
 
Constructor Summary
AbstractFormatter()
           
 
Method Summary
abstract  java.lang.String doFormat(ExtendedLogRecord record)
           
 java.lang.String format(ExtendedLogRecord record)
          Formats the given LogRecord.
 java.lang.String format(java.util.logging.LogRecord record)
          
 java.lang.String formatMessage(ExtendedLogRecord record)
           
protected  ExtendedLogger getLogger()
          Return an instance specific logger to be used by the component itself.
protected  ObjectStore getLoggerRepository()
          Return the ObjectStore this component is attached to.
 MessageProperties getMessageProperties()
          Specifiy Properties for the component.
protected  ExtendedLogger getNonFloodingLogger()
          Frequently called methods in log4j components can invoke this method in order to avoid flooding the output when logging lasting error conditions.
protected  boolean getProperty(java.lang.String name, boolean defaultValue)
          Get an property value out of the LogManager by name.
protected  int getProperty(java.lang.String name, int defaultValue)
          Get an property value out of the LogManager by name.
protected  java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)
          Get an property value out of the LogManager by name.
 boolean ignoresThrowable()
          Formatter ignores throwables in output?
protected  void resetErrorCount()
          Called by derived classes when they deem that the component has recovered from an erroneous state.
 void setIgnoresThrowable(boolean ignoresThrowable)
          Formatter ignores throwables in output?
 void setObjectStore(ObjectStore rep)
          Set the owning repository.
 
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
 
Methods inherited from interface org.x4juli.global.spi.OptionHandler
activateOptions
 
Methods inherited from interface org.x4juli.global.spi.ExtendedFormatter
formatMessage, getHead, getTail
 

Field Detail

repository

protected ObjectStore repository
Store for this component.


manager

protected final java.util.logging.LogManager manager
LogManager for easy access.


ignoresThrowable

protected boolean ignoresThrowable
Formatter ignores throwables in output or not.


logger

private ExtendedLogger logger

errorCount

private int errorCount
Constructor Detail

AbstractFormatter

public AbstractFormatter()
Method Detail

getMessageProperties

public MessageProperties getMessageProperties()
Specifiy Properties for the component. Default Implementation returns null. Specifiy Properties for the component. Default Implementation returns null.

Specified by:
getMessageProperties in interface Component
Returns:
the key for the Properties for the component
Since:
0.5

setObjectStore

public void setObjectStore(ObjectStore rep)
Set the owning repository. The owning repository cannot be set more than once. Set owning object repository for this component. This operation can only be performed once. Once set, the owning repository cannot be changed.

Specified by:
setObjectStore in interface Component
Parameters:
rep - The repository where the configuration is stored
Since:
0.5

ignoresThrowable

public boolean ignoresThrowable()
Formatter ignores throwables in output?

Specified by:
ignoresThrowable in interface ExtendedFormatter
Returns:
whether throwables are ignored or not.
Since:
0.5

setIgnoresThrowable

public void setIgnoresThrowable(boolean ignoresThrowable)
Formatter ignores throwables in output?

Parameters:
ignoresThrowable - whether throwables are ignored or not.
Since:
0.5

format

public final java.lang.String format(java.util.logging.LogRecord record)

Specified by:
format in interface Formatter
Since:
0.5

format

public java.lang.String format(ExtendedLogRecord record)
Formats the given LogRecord.

Specified by:
format in interface ExtendedFormatter
Parameters:
record - containing the information to generate and beautify Output
Returns:
the formatted information.
Since:
0.5
See Also:
Formatter.format(java.util.logging.LogRecord)

doFormat

public abstract java.lang.String doFormat(ExtendedLogRecord record)
Since:
0.5
See Also:
Formatter.format(java.util.logging.LogRecord)

formatMessage

public java.lang.String formatMessage(ExtendedLogRecord record)
Since:
0.5
See Also:
Formatter.formatMessage(java.util.logging.LogRecord)

resetErrorCount

protected void resetErrorCount()
Called by derived classes when they deem that the component has recovered from an erroneous state.


getLoggerRepository

protected ObjectStore getLoggerRepository()
Return the ObjectStore this component is attached to.

Returns:
Owning ObjectStore
Since:
0.5

getLogger

protected ExtendedLogger getLogger()
Return an instance specific logger to be used by the component itself. This logger is not intended to be accessed by the end-user, hence the protected keyword.

This logger always sends output to an ConsoleHandler, which outputs to System.err

Returns:
A Logger instance for the concrete formatter.
Since:
0.5

getNonFloodingLogger

protected ExtendedLogger getNonFloodingLogger()
Frequently called methods in log4j components can invoke this method in order to avoid flooding the output when logging lasting error conditions.

Returns:
a regular logger, or a NOPLogger if called too frequently.
Since:
0.5

getProperty

protected java.lang.String getProperty(java.lang.String name,
                                       java.lang.String defaultValue)
Get an property value out of the LogManager by name.

Parameters:
name - of the parameter to be obtained
defaultValue -
Returns:
the value of the given property, if null defaultValue

getProperty

protected int getProperty(java.lang.String name,
                          int defaultValue)
Get an property value out of the LogManager by name.

Parameters:
name - of the parameter to be obtained
defaultValue -
Returns:
the value of the given property, if null defaultValue

getProperty

protected boolean getProperty(java.lang.String name,
                              boolean defaultValue)
Get an property value out of the LogManager by name.

Parameters:
name - of the parameter to be obtained
defaultValue -
Returns:
the value of the given property, if null defaultValue


${license_html}