de.unkrig.commons.util.logging.formatter
Class SelectiveFormatter

java.lang.Object
  extended by java.util.logging.Formatter
      extended by de.unkrig.commons.util.logging.formatter.SelectiveFormatter

public class SelectiveFormatter
extends java.util.logging.Formatter

A Formatter calls one of two delegates, depending on the evaluation result of a LogRecord Predicate.


Constructor Summary
SelectiveFormatter(Predicate<java.util.logging.LogRecord> predicate, java.util.logging.Formatter delegate1, java.util.logging.Formatter delegate2)
           
 
Method Summary
 java.lang.String format(java.util.logging.LogRecord logRecord)
          Calls delegate1 if the predicate evaluates to true for the logRecord, otherwise delegate2.
static java.util.logging.Formatter loggerLevelGreaterThan(java.util.logging.Level threshold, java.util.logging.Formatter delegate1, java.util.logging.Formatter delegate2)
          Returns a Formatter that for each LogRecord invokes delegate1 if the level of the processing Logger is greater than threshold, and for all other the delegate2.
static java.util.logging.Formatter logRecordLevelGreaterThan(java.util.logging.Level threshold, java.util.logging.Formatter delegate1, java.util.logging.Formatter delegate2)
          Returns a Formatter that for each LogRecord invokes delegate1 if the level of the log record is greater than ("more severe than") threshold, and for all other the delegate2.
 
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

SelectiveFormatter

public SelectiveFormatter(Predicate<java.util.logging.LogRecord> predicate,
                          java.util.logging.Formatter delegate1,
                          java.util.logging.Formatter delegate2)
Parameters:
delegate1 - Is called for LogRecord for which the predicate evaluates to true
delegate2 - Is called for LogRecord for which the predicate evaluates to false
Method Detail

format

public java.lang.String format(java.util.logging.LogRecord logRecord)
Calls delegate1 if the predicate evaluates to true for the logRecord, otherwise delegate2.

Specified by:
format in class java.util.logging.Formatter
See Also:
SelectiveFormatter(Predicate, Formatter, Formatter)

loggerLevelGreaterThan

public static final java.util.logging.Formatter loggerLevelGreaterThan(java.util.logging.Level threshold,
                                                                       java.util.logging.Formatter delegate1,
                                                                       java.util.logging.Formatter delegate2)
Returns a Formatter that for each LogRecord invokes delegate1 if the level of the processing Logger is greater than threshold, and for all other the delegate2.

A typical application is to format log records WITHOUT stack traces, except if the logger's level is set to Level.FINE or lower.


logRecordLevelGreaterThan

public static final java.util.logging.Formatter logRecordLevelGreaterThan(java.util.logging.Level threshold,
                                                                          java.util.logging.Formatter delegate1,
                                                                          java.util.logging.Formatter delegate2)
Returns a Formatter that for each LogRecord invokes delegate1 if the level of the log record is greater than ("more severe than") threshold, and for all other the delegate2.

A typical application is to format log records WITHOUT stack traces, except if the logger's level is set to Level.FINE or lower.