public class CollectorFormatter
extends java.util.logging.Formatter
The LogManager properties are:
SeverityComparator
)
CompactFormatter
)
Modifier and Type | Field and Description |
---|---|
private java.util.Comparator<? super java.util.logging.LogRecord> |
comparator
The comparator used to pick the log record to format.
|
private long |
count
The number of log records that have been formatted.
|
private java.lang.String |
fmt
The message format string used as the formatted output.
|
private java.util.logging.Formatter |
formatter
The formatter used to format the chosen log record.
|
private static long |
INIT_TIME
Avoid depending on JMX runtime bean to get the start time.
|
private java.util.logging.LogRecord |
last
The last accepted record.
|
private long |
maxMillis
The newest log record time.
|
private long |
minMillis
The eldest log record time.
|
private long |
thrown
The number of log records that have been formatted with a thrown object.
|
Constructor and Description |
---|
CollectorFormatter()
Creates the formatter using the LogManager defaults.
|
CollectorFormatter(java.lang.String format)
Creates the formatter using the given format.
|
CollectorFormatter(java.lang.String format,
java.util.logging.Formatter f,
java.util.Comparator<? super java.util.logging.LogRecord> c)
Creates the formatter using the given values.
|
Modifier and Type | Method and Description |
---|---|
private void |
accept(java.util.logging.LogRecord record)
Updates the summary statistics but does not store the given LogRecord.
|
private boolean |
acceptAndUpdate(java.util.logging.LogRecord e,
java.util.logging.LogRecord u)
Updates the summary statistics and stores given LogRecord if the expected
record matches the current record.
|
protected java.util.logging.LogRecord |
apply(java.util.logging.LogRecord t,
java.util.logging.LogRecord u)
Used to choose the collected LogRecord.
|
protected java.lang.String |
finish(java.lang.String s)
Applied to the head, format, and tail returned by the target formatter.
|
java.lang.String |
format(java.util.logging.LogRecord record)
Accumulates log records which will be used to produce the final output.
|
private java.lang.String |
formatRecord(java.util.logging.Handler h,
boolean reset)
Formats the given record with the head and tail.
|
java.lang.String |
getTail(java.util.logging.Handler h)
Formats the collected LogRecord and summary statistics.
|
private java.util.Comparator<? super java.util.logging.LogRecord> |
initComparator(java.lang.String p)
Gets and creates the comparator from the LogManager or returns the
default comparator.
|
private java.lang.String |
initFormat(java.lang.String p)
Gets the message format string from the LogManager or creates the default
message format string.
|
private java.util.logging.Formatter |
initFormatter(java.lang.String p)
Gets and creates the formatter from the LogManager or creates the default
formatter.
|
private java.util.logging.LogRecord |
peek()
Peek at the current log record.
|
private void |
reset()
Resets all of the collected summary statistics including the LogRecord.
|
java.lang.String |
toString()
Formats the collected LogRecord and summary statistics.
|
private static final long INIT_TIME
private final java.lang.String fmt
private final java.util.logging.Formatter formatter
private final java.util.Comparator<? super java.util.logging.LogRecord> comparator
private java.util.logging.LogRecord last
private long count
private long thrown
private long minMillis
private long maxMillis
public CollectorFormatter()
java.lang.SecurityException
- if a security manager exists and the caller
does not have LoggingPermission("control").java.lang.reflect.UndeclaredThrowableException
- if there are problems loading from
the LogManager.public CollectorFormatter(java.lang.String format)
format
- the message format or null to use the LogManager default.java.lang.SecurityException
- if a security manager exists and the caller
does not have LoggingPermission("control").java.lang.reflect.UndeclaredThrowableException
- if there are problems loading from
the LogManager.public CollectorFormatter(java.lang.String format, java.util.logging.Formatter f, java.util.Comparator<? super java.util.logging.LogRecord> c)
format
- the format string or null to use the LogManager default.f
- the formatter used on the collected log record or null to
specify no formatter.c
- the comparator used to determine which log record to format or
null to specify no comparator.java.lang.SecurityException
- if a security manager exists and the caller
does not have LoggingPermission("control").java.lang.reflect.UndeclaredThrowableException
- if there are problems loading from
the LogManager.public java.lang.String format(java.util.logging.LogRecord record)
getTail(java.util.logging.Handler)
method which also
resets this formatter back to its original state.format
in class java.util.logging.Formatter
record
- the record to store.java.lang.NullPointerException
- if the given record is null.public java.lang.String getTail(java.util.logging.Handler h)
java.text
argument indexes are assigned
to the following properties:
head
the
head string
returned from the target formatter and
finished by this formatter.
formatted
the current log record
formatted by
the target formatter and finished
by this formatter.
tail
the
tail string
returned from the target formatter and
finished by this formatter.
count
the total number of log records
consumed by this formatter.
remaining
the count minus one.
thrown
the total number of log records
consumed by this formatter with an assigned
throwable.
normal messages
the count minus the thrown.
minMillis
the eldest log record event time
consumed by this formatter. If no records were
formatted then this is set to the approximate start time of the JVM. By
default this parameter is defined as a number. The format type and format
style rules from the MessageFormat
should be used to
convert this to a date or time.
maxMillis
the most recent log record event time
consumed by this formatter. If no records were
formatted then this is set to the current time. By default this parameter
is defined as a number. The format type and format style rules from the
MessageFormat
should be used to convert this to a date
or time.
getTail
in class java.util.logging.Formatter
h
- the handler or null.public java.lang.String toString()
toString
in class java.lang.Object
getTail(java.util.logging.Handler)
protected java.util.logging.LogRecord apply(java.util.logging.LogRecord t, java.util.logging.LogRecord u)
t
- the current record.u
- the record that could replace the current.java.lang.NullPointerException
- may occur if either record is null.private void accept(java.util.logging.LogRecord record)
record
- the LogRecord used to collect statistics.private void reset()
private java.lang.String formatRecord(java.util.logging.Handler h, boolean reset)
h
- the Handler or null.reset
- true if the summary statistics and LogRecord should be reset
back to initial values.getTail(java.util.logging.Handler)
protected java.lang.String finish(java.lang.String s)
s
- the string to transform.java.lang.NullPointerException
- if the given string is null.private java.util.logging.LogRecord peek()
private boolean acceptAndUpdate(java.util.logging.LogRecord e, java.util.logging.LogRecord u)
e
- the expected record.u
- the update record.private java.lang.String initFormat(java.lang.String p)
p
- the class name prefix.private java.util.logging.Formatter initFormatter(java.lang.String p)
p
- the class name prefix.java.lang.reflect.UndeclaredThrowableException
- if the formatter can not be created.private java.util.Comparator<? super java.util.logging.LogRecord> initComparator(java.lang.String p)
p
- the class name prefix.java.lang.IllegalArgumentException
- if it was specified that the comparator
should be reversed but no initial comparator was specified.java.lang.reflect.UndeclaredThrowableException
- if the comparator can not be
created.