Class JulFormatter
- java.lang.Object
-
- java.util.logging.Formatter
-
- pl.morgwai.base.logging.JulFormatter
-
public class JulFormatter extends Formatter
A text log formatter similar toSimpleFormatter
that additionally allows to format stack trace elements and to add log sequence id and thread id to log entries.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_FORMAT
"%7$5d %8$3d %4$7s %1$tF %1$tT.%1$tL %3$s %5$s %6$s%n"static String
FORMAT_PROPERTY_NAME
Name of the logging or system property containing the main format for each record.static String
JUL_SIMPLE_FORMAT_PROPERTY_NAME
"java.util.logging.SimpleFormatter.format"static String
STACKFRAME_FORMAT_PROPERTY_NAME
Name of the logging or system property containing the format for stack frames of logged throwables.
-
Constructor Summary
Constructors Constructor Description JulFormatter()
Creates a new formatter configured using either system properties or logging properties.JulFormatter(String format, String stackFrameFormat)
Creates a new formatter configured using supplied params.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(LogRecord record)
Formats the givenrecord
.-
Methods inherited from class java.util.logging.Formatter
formatMessage, getHead, getTail
-
-
-
-
Field Detail
-
FORMAT_PROPERTY_NAME
public static final String FORMAT_PROPERTY_NAME
Name of the logging or system property containing the main format for each record.- See Also:
format(LogRecord)
-
STACKFRAME_FORMAT_PROPERTY_NAME
public static final String STACKFRAME_FORMAT_PROPERTY_NAME
Name of the logging or system property containing the format for stack frames of logged throwables.- See Also:
format(LogRecord)
-
DEFAULT_FORMAT
public static final String DEFAULT_FORMAT
"%7$5d %8$3d %4$7s %1$tF %1$tT.%1$tL %3$s %5$s %6$s%n"- See Also:
- Constant Field Values
-
JUL_SIMPLE_FORMAT_PROPERTY_NAME
public static final String JUL_SIMPLE_FORMAT_PROPERTY_NAME
"java.util.logging.SimpleFormatter.format"- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JulFormatter
public JulFormatter(String format, String stackFrameFormat)
Creates a new formatter configured using supplied params.- Parameters:
format
- the main format for log records. If it'snull
then "%7$5d %8$3d %4$7s %1$tF %1$tT.%1$tL %3$s %5$s %6$s%n" is used.stackFrameFormat
- format for stack trace elements of logged throwables.- See Also:
format(LogRecord)
-
JulFormatter
public JulFormatter()
Creates a new formatter configured using either system properties or logging properties. If both are present, system properties take precedence.By default the value of
FORMAT_PROPERTY_NAME
property is used as the main format for log records. If it is not present in either logging or system properties, then "java.util.logging.SimpleFormatter.format" property is read and if present, its value is prepended with"%7$5d %8$3d "
and used instead. if it is also absent, then "%7$5d %8$3d %4$7s %1$tF %1$tT.%1$tL %3$s %5$s %6$s%n" is used.The value of
STACKFRAME_FORMAT_PROPERTY_NAME
property is used as the format for stack trace elements. If it is not present in either logging or system properties, thennull
is passed.- See Also:
JulFormatter(String, String)
,format(LogRecord)
-
-
Method Detail
-
format
public String format(LogRecord record)
Formats the givenrecord
.The result is obtained by running
String.format(format, timestamp, source, loggerName, level, message, formattedThrown, logId, threadId)
whereformat
is obtained from eitherFORMAT_PROPERTY_NAME
property or the first param ofJulFormatter(String, String)
.formattedThrown
is obtained by callingrecord.getThrown().toString()
and appending
String.format(stackFrameFormat, logId, className, methodName, FileName, lineNumber, moduleName, moduleVersion, classLoaderName)
wherestackFrameFormat
is obtained from eitherSTACKFRAME_FORMAT_PROPERTY_NAME
property or the second param ofJulFormatter(String, String)
.
IfstackFrameFormat
isnull
thenThrowable.printStackTrace(java.io.PrintStream)
is called instead ofString.format(String, Object...)
.
-
-