Class StructuredFormatter
- Direct Known Subclasses:
JsonFormatter,XmlFormatter
record.
Note that including details can be expensive in terms of calculating the caller.
By default the record delimiter is set to \n.
- Author:
- James R. Perkins
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines the way a cause will be formatted.protected static interfaceA generator used to create the structured output.static enumThe key used for the structured log record data. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedStructuredFormatter(String keyOverrides) protectedStructuredFormatter(Map<StructuredFormatter.Key, String> keyOverrides) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafter(StructuredFormatter.Generator generator, ExtLogRecord record) Invoked after the structured data has been added to the generator.protected voidbefore(StructuredFormatter.Generator generator, ExtLogRecord record) Invoked before the structured data is added to the generator.protected abstract StructuredFormatter.GeneratorcreateGenerator(Writer writer) Creates the generator used to create the structured data.final Stringformat(ExtLogRecord record) Format a message using an extended log record.Returns the current formatter used to format a records date and time.Get the current output type for exceptions.protected final StringgetKey(StructuredFormatter.Key defaultKey) Checks to see if the key should be overridden.A string representation of the key overrides.Returns the value set for meta data.Returns the character used to indicate the record has is complete.Returns the current zone id used for the date and time formatter.booleanDetermines whether or not this formatter will require caller, source level, information when a log record is formatted.protected booleanChecks the exception output type and determines if detailed output should be written.protected booleanChecks the exception output type and determines if formatted output should be written.booleanIndicates whether or not details should be printed.voidsetDateFormat(String pattern) Sets the pattern to use when formatting the date.voidsetExceptionOutputType(StructuredFormatter.ExceptionOutputType exceptionOutputType) Set the output type for exceptions.voidsetMetaData(String metaData) Sets the meta data to use in the structured format.voidsetPrintDetails(boolean printDetails) Sets whether or not details should be printed.voidsetRecordDelimiter(String eorDelimiter) Sets the value to be used to indicate the end of a record.voidMethods inherited from class org.jboss.logmanager.ExtFormatter
formatMethods inherited from class java.util.logging.Formatter
formatMessage, getHead, getTail
-
Constructor Details
-
StructuredFormatter
protected StructuredFormatter() -
StructuredFormatter
-
StructuredFormatter
-
-
Method Details
-
createGenerator
Creates the generator used to create the structured data.- Returns:
- the generator to use
- Throws:
Exception- if an error occurs creating the generator
-
before
protected void before(StructuredFormatter.Generator generator, ExtLogRecord record) throws Exception Invoked before the structured data is added to the generator.- Parameters:
generator- the generator to userecord- the log record- Throws:
Exception
-
after
Invoked after the structured data has been added to the generator.- Parameters:
generator- the generator to userecord- the log record- Throws:
Exception
-
getKey
Checks to see if the key should be overridden.- Parameters:
defaultKey- the default key- Returns:
- the overridden key or the default key if no override exists
-
format
Description copied from class:ExtFormatterFormat a message using an extended log record.- Specified by:
formatin classExtFormatter- Parameters:
record- the log record- Returns:
- the formatted message
-
isCallerCalculationRequired
public boolean isCallerCalculationRequired()Description copied from class:ExtFormatterDetermines whether or not this formatter will require caller, source level, information when a log record is formatted.- Overrides:
isCallerCalculationRequiredin classExtFormatter- Returns:
trueif the formatter will need caller information, otherwisefalse- See Also:
-
getKeyOverrides
A string representation of the key overrides. The default isnull.- Returns:
- a string representation of the key overrides or
nullif no overrides were configured
-
getRecordDelimiter
Returns the character used to indicate the record has is complete. This defaults to\nand may benullif no end of record character is desired.- Returns:
- the end of record delimiter or
nullif no delimiter is desired
-
setRecordDelimiter
Sets the value to be used to indicate the end of a record. If set tonullno delimiter will be used at the end of the record.- Parameters:
eorDelimiter- the delimiter to be used ornullto not use a delimiter
-
getMetaData
Returns the value set for meta data.The value is a string where key/value pairs are separated by commas. The key and value are separated by an equal sign.
- Returns:
- the meta data string or
nullif one was not set - See Also:
-
setMetaData
Sets the meta data to use in the structured format.The value is a string where key/value pairs are separated by commas. The key and value are separated by an equal sign.
- Parameters:
metaData- the meta data to set ornullto not format any meta data- See Also:
-
getDateTimeFormatter
Returns the current formatter used to format a records date and time.- Returns:
- the current formatter
-
setDateFormat
Sets the pattern to use when formatting the date. The pattern must be a validDateTimeFormatter.ofPattern(String)pattern.If the pattern is
nulla default formatter will be used. The zone id will always be appended to the formatter. By default the zone id will default to the systems zone id.- Parameters:
pattern- the pattern to use ornullto use a default pattern
-
getZoneId
Returns the current zone id used for the date and time formatter.- Returns:
- the current zone id
-
setZoneId
Sets theZoneIdto use when formatting the date and time from theLogRecord.The rules of the id must conform to the rules specified on
ZoneId.of(String).- Parameters:
zoneId- the zone id ornullto use the system default- See Also:
-
isPrintDetails
public boolean isPrintDetails()Indicates whether or not details should be printed.- Returns:
trueif details should be printed, otherwisefalse
-
setPrintDetails
public void setPrintDetails(boolean printDetails) Sets whether or not details should be printed.Printing the details can be expensive as the values are retrieved from the caller. The details include the source class name, source file name, source method name and source line number.
- Parameters:
printDetails-trueif details should be printed
-
getExceptionOutputType
Get the current output type for exceptions.- Returns:
- the output type for exceptions
-
setExceptionOutputType
Set the output type for exceptions. The default isDETAILED.- Parameters:
exceptionOutputType- the desired output type, ifnullStructuredFormatter.ExceptionOutputType.DETAILEDis used
-
isDetailedExceptionOutputType
protected boolean isDetailedExceptionOutputType()Checks the exception output type and determines if detailed output should be written.- Returns:
trueif detailed output should be written, otherwisefalse
-
isFormattedExceptionOutputType
protected boolean isFormattedExceptionOutputType()Checks the exception output type and determines if formatted output should be written. The formatted output is equivalent toThrowable.printStackTrace().- Returns:
trueif formatted exception output should be written, otherwisefalse
-