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

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

public class PrintfFormatter
extends java.util.logging.Formatter

A Formatter that formats a LogRecord through a format string (as described for Formatter) which is specified through the de.unkrig.commons.util.logging.FormatFormatter.format logging property.

Notice:
Since Java 7, the SimpleFormatter also has a '.format' property and thus implements the key feature of this class.

This class is a COPY of de.unkrig.ext.logging.formatter.PrintfFormatter, and should be kept in sync with that.


Field Summary
static PrintfFormatter BENCHMARK
          A format for benchmarking:
%12$s %10$-20s %3$2d %8$s%n
Example: 3.000000; 2.000000; 1.000000 MyClass 0 Message
static PrintfFormatter COMPACT
          A compact one-line format:
%4$s %6$s::%7$s %8$s%9$s%n
Examples: FINE pkg.MyClass::main Log message #1 FINE pkg.MyClass::main Log message #2 java.io.IOException: Exception message at pkg.MyClass.main()
static PrintfFormatter DEFAULT
          The default format format PrintfFormatter().
static PrintfFormatter MESSAGE
          
%8$s%n
Example: Log message
static PrintfFormatter MESSAGE_AND_EXCEPTION
          
%8$s%n
Examples: Log message Log message: java.io.FileNotFoundException: Exception message
static PrintfFormatter MESSAGE_AND_STACK_TRACE
          
%8$s%9$s%n
Examples: Log message #1 Log message #2 java.io.IOException: Exception message at pkg.MyClass.main()
static PrintfFormatter SIMPLE
          A simple one-line format:
%5$tF %5$tT.%5$tL %10$-20s %3$2d %8$s%9$s%n
Example: 2012-03-08 10:10:28.515 MyClass 0 Log message #1 2012-03-08 10:10:28.516 MyClass 0 Log message #2 java.io.IOException: Exception message at pkg.MyClass.main()
static PrintfFormatter TIME_MESSAGE
          
%5$tF %5$tT.%5$tL %8$s%n
Example: 2012-12-31 23:59:59.999 Message
 
Constructor Summary
PrintfFormatter()
          The format string is retrieved from the de.unkrig.commons.util.logging.formatter.PrintfFormatter.format logging property.
PrintfFormatter(java.lang.String propertyNamePrefix)
          One-arg constructor for proxies.
PrintfFormatter(java.lang.String format, int dummy)
          A format string with placeholders as described for format(LogRecord).
 
Method Summary
 java.lang.String format(java.util.logging.LogRecord record)
          Formats a LogRecord with a PRINTF format string.
 java.lang.String getFormat()
           
 void setFormat(java.lang.String 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
 

Field Detail

COMPACT

public static final PrintfFormatter COMPACT
A compact one-line format:
%4$s %6$s::%7$s %8$s%9$s%n
Examples:
 FINE pkg.MyClass::main Log message #1

 FINE pkg.MyClass::main Log message #2
 java.io.IOException: Exception message
     at pkg.MyClass.main()
 


MESSAGE_AND_EXCEPTION

public static final PrintfFormatter MESSAGE_AND_EXCEPTION
%8$s%n
Examples:
 Log message
 Log message: java.io.FileNotFoundException: Exception message
 


MESSAGE

public static final PrintfFormatter MESSAGE
%8$s%n
Example:
 Log message
 


MESSAGE_AND_STACK_TRACE

public static final PrintfFormatter MESSAGE_AND_STACK_TRACE
%8$s%9$s%n
Examples:
 Log message #1

 Log message #2
 java.io.IOException: Exception message
     at pkg.MyClass.main()
 


SIMPLE

public static final PrintfFormatter SIMPLE
A simple one-line format:
%5$tF %5$tT.%5$tL %10$-20s %3$2d %8$s%9$s%n
Example:
 2012-03-08 10:10:28.515 MyClass               0 Log message #1

 2012-03-08 10:10:28.516 MyClass               0 Log message #2
 java.io.IOException: Exception message
     at pkg.MyClass.main()
 


TIME_MESSAGE

public static final PrintfFormatter TIME_MESSAGE
%5$tF %5$tT.%5$tL %8$s%n
Example:
 2012-12-31 23:59:59.999 Message
 


BENCHMARK

public static final PrintfFormatter BENCHMARK
A format for benchmarking:
%12$s %10$-20s %3$2d %8$s%n
Example:
     3.000000;    2.000000;    1.000000 MyClass               0 Message
 


DEFAULT

public static final PrintfFormatter DEFAULT
The default format format PrintfFormatter().

The default format is the SIMPLE.

Constructor Detail

PrintfFormatter

public PrintfFormatter()
The format string is retrieved from the de.unkrig.commons.util.logging.formatter.PrintfFormatter.format logging property.

Logging properties are typically defined in file $JAVA_HOME/jre/lib/logging.properties.


PrintfFormatter

public PrintfFormatter(@Nullable
                       java.lang.String propertyNamePrefix)
One-arg constructor for proxies.

See Also:
format(LogRecord)

PrintfFormatter

public PrintfFormatter(java.lang.String format,
                       int dummy)
A format string with placeholders as described for format(LogRecord).

The following special format strings are recognized:

See Also:
format(LogRecord)
Method Detail

setFormat

public final void setFormat(java.lang.String format)
Parameters:
format - null defines a default format.

getFormat

public java.lang.String getFormat()
Returns:
The currently configured format string.

format

public java.lang.String format(java.util.logging.LogRecord record)
Formats a LogRecord with a PRINTF format string.
PlaceholderDescriptionExample
%1$d Sequence number  
%2$s Logger name  
%3$d Thread ID 1
%4$s Level FINE
%5$tF %5$tT.%5$tL Date/time 2012-03-08 10:10:28.468
%6$s Source class name pkg.MyClass
%7$s Source method name main
%8$s Message  
%9$s Colon, line break; type, message and stack trace (with no trailing line break) of the (optional) throwable preceeding-text:
pkg.MyException: Exception message
    at pkg.Class.method(File.java:123)
    at Main.main(Main.java:20)
%10$s Simple source class name MyClass
%11$s Colon, space, throwable converted to string (typically class name, colon, space, localized message) preceeding-text: pkg.MyEception
%12$s Real, CPU and user time in milliseconds since this thread last logged to this handler
3.000000;    2.000000;    1.000000
%n Line separator  
%% Percent character ('%')  

Specified by:
format in class java.util.logging.Formatter