public class CompactFormatter
extends java.util.logging.Formatter
alternate
fixed width format.
The LogManager properties are:
format
string used to transform the output. The format string can be used to
fix the output size. (defaults to "%7$#.160s%n")Modifier and Type | Class and Description |
---|---|
private class |
CompactFormatter.Alternate
Used to format two arguments as fixed length message.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
fmt
Holds the java.util.Formatter pattern.
|
Constructor and Description |
---|
CompactFormatter()
Creates an instance with a default format pattern.
|
CompactFormatter(java.lang.String format)
Creates an instance with the given format pattern.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Throwable |
apply(java.lang.Throwable t)
Chooses a single throwable from the cause chain that will be formatted.
|
private boolean |
defaultIgnore(java.lang.StackTraceElement s)
Determines if a stack frame should be ignored as the cause of an error.
|
private java.lang.String |
findAndFormat(java.lang.StackTraceElement[] trace)
Finds and formats the first stack frame of interest.
|
java.lang.String |
format(java.util.logging.LogRecord record)
Format the given log record and returns the formatted string.
|
java.lang.String |
formatBackTrace(java.util.logging.LogRecord record)
Formats the back trace for the given log record.
|
java.lang.String |
formatLevel(java.util.logging.LogRecord record)
Formats the level property of the given log record.
|
java.lang.String |
formatLoggerName(java.util.logging.LogRecord record)
Formats the logger name property of the given log record.
|
java.lang.String |
formatMessage(java.util.logging.LogRecord record)
Formats message for the log record.
|
java.lang.String |
formatMessage(java.lang.Throwable t)
Formats the message from the thrown property of the log record.
|
java.lang.String |
formatSource(java.util.logging.LogRecord record)
Formats the source from the given log record.
|
private java.lang.String |
formatStackTraceElement(java.lang.StackTraceElement s)
Formats a stack trace element into a simple call site.
|
java.lang.String |
formatThrown(java.util.logging.LogRecord record)
Formats the thrown property of a LogRecord.
|
protected boolean |
ignore(java.lang.StackTraceElement s)
Determines if a stack frame should be ignored as the cause of an error.
|
private java.lang.String |
initFormat(java.lang.String p)
Creates the format pattern for this formatter.
|
private static boolean |
isNullOrSpaces(java.lang.String s)
Determines is the given string is null or spaces.
|
private boolean |
isReflection(java.lang.StackTraceElement s)
Determines if a stack trace element represents a reflection frame.
|
private boolean |
isStaticUtility(java.lang.StackTraceElement s)
Determines if a stack frame is for a static utility class.
|
private boolean |
isSynthetic(java.lang.StackTraceElement s)
Determines if a stack trace element is for a synthetic method.
|
private boolean |
isUnknown(java.lang.StackTraceElement s)
Determines if a stack trace element has an unknown line number or a
native line number.
|
private static java.lang.String |
replaceClassName(java.lang.String msg,
java.lang.Object[] p)
Searches the given message for all instances fully qualified class name
with simple class name based off of the types contained in the given
parameter array.
|
private static java.lang.String |
replaceClassName(java.lang.String msg,
java.lang.Throwable t)
Searches the given message for all instances fully qualified class name
with simple class name based off of the types contained in the given
parameter array.
|
private static java.lang.String |
simpleClassName(java.lang.String name)
Converts a fully qualified class name to a simple class name.
|
private static java.lang.String |
simpleFileName(java.lang.String name)
Converts a file name with an extension to a file name without an
extension.
|
protected java.lang.String |
toAlternate(java.lang.String s)
Defines the alternate format.
|
public CompactFormatter()
public CompactFormatter(java.lang.String format)
format
- the pattern
or null to use the
LogManager default. The arguments are described in the
format
method.public java.lang.String format(java.util.logging.LogRecord record)
java.util
argument indexes are assigned to the following properties:
format
- the java.util.Formatter
format string specified in the
<formatter-name>.format property or the format that was given when
this formatter was created.date
- a Date
object representing
event time of the log record.source
- a string representing the caller, if available;
otherwise, the logger's name.logger
- the logger's name.level
- the
log level.message
- the formatted log message returned from the
formatMessage(LogRecord)
method.thrown
- a string representing the
throwable associated with the log record
and a relevant stack trace element if available. Otherwise, an empty
string is used.message|thrown
The message and the thrown properties joined
as one parameter. This parameter supports
alternate
form.thrown|message
The thrown and message properties joined as
one parameter. This parameter supports
alternate
form.format
in class java.util.logging.Formatter
record
- to format.java.lang.NullPointerException
- if the given record is null.public java.lang.String formatMessage(java.util.logging.LogRecord record)
formatMessage
in class java.util.logging.Formatter
record
- the log record.public java.lang.String formatMessage(java.lang.Throwable t)
t
- the throwable to format.public java.lang.String formatLevel(java.util.logging.LogRecord record)
record
- the record.java.lang.NullPointerException
- if the given record is null.public java.lang.String formatSource(java.util.logging.LogRecord record)
record
- the record.java.lang.NullPointerException
- if the given record is null.public java.lang.String formatLoggerName(java.util.logging.LogRecord record)
record
- the record.java.lang.NullPointerException
- if the given record is null.public java.lang.String formatThrown(java.util.logging.LogRecord record)
record
- the record.java.lang.NullPointerException
- if the given record is null.apply(java.lang.Throwable)
,
formatBackTrace(java.util.logging.LogRecord)
public java.lang.String formatBackTrace(java.util.logging.LogRecord record)
record
- the log record to format.java.lang.NullPointerException
- if the given record is null.apply(java.lang.Throwable)
,
formatThrown(java.util.logging.LogRecord)
,
ignore(java.lang.StackTraceElement)
private java.lang.String findAndFormat(java.lang.StackTraceElement[] trace)
trace
- the fill stack to examine.java.lang.NullPointerException
- if stack trace element array is null.private java.lang.String formatStackTraceElement(java.lang.StackTraceElement s)
s
- the stack trace element to format.java.lang.NullPointerException
- if stack trace element is null.formatThrown(java.util.logging.LogRecord)
protected java.lang.Throwable apply(java.lang.Throwable t)
t
- the throwable from the log record.formatThrown(java.util.logging.LogRecord)
protected boolean ignore(java.lang.StackTraceElement s)
s
- the stack trace element.formatThrown(java.util.logging.LogRecord)
protected java.lang.String toAlternate(java.lang.String s)
s
- any string or null.private boolean defaultIgnore(java.lang.StackTraceElement s)
s
- the stack trace element.private boolean isStaticUtility(java.lang.StackTraceElement s)
s
- the stack trace element.private boolean isSynthetic(java.lang.StackTraceElement s)
s
- the stack trace element.java.lang.NullPointerException
- if stack trace element is null.private boolean isUnknown(java.lang.StackTraceElement s)
s
- the stack trace element.java.lang.NullPointerException
- if stack trace element is null.private boolean isReflection(java.lang.StackTraceElement s)
s
- the stack trace element.java.lang.NullPointerException
- if stack trace element is null.private java.lang.String initFormat(java.lang.String p)
p
- the class name prefix.java.lang.NullPointerException
- if the given class name is null.private static java.lang.String replaceClassName(java.lang.String msg, java.lang.Throwable t)
msg
- the message.t
- the throwable cause chain to search or null.private static java.lang.String replaceClassName(java.lang.String msg, java.lang.Object[] p)
msg
- the message or null.p
- the parameter array or null.private static java.lang.String simpleClassName(java.lang.String name)
name
- the fully qualified class name or null.private static java.lang.String simpleFileName(java.lang.String name)
name
- the full file name or null.private static boolean isNullOrSpaces(java.lang.String s)
s
- the string or null.