public abstract class StructuredFormatter extends ExtFormatter
record
.
Note that including details can be expensive in terms of calculating the caller.
By default the record delimiter is set to \n
.
Modifier and Type | Class and Description |
---|---|
static class |
StructuredFormatter.ExceptionOutputType
Defines the way a cause will be formatted.
|
protected static interface |
StructuredFormatter.Generator
A generator used to create the structured output.
|
static class |
StructuredFormatter.Key
The key used for the structured log record data.
|
Modifier | Constructor and Description |
---|---|
protected |
StructuredFormatter() |
protected |
StructuredFormatter(Map<StructuredFormatter.Key,String> keyOverrides) |
protected |
StructuredFormatter(String keyOverrides) |
Modifier and Type | Method and Description |
---|---|
protected void |
after(StructuredFormatter.Generator generator,
ExtLogRecord record)
Invoked after the structured data has been added to the generator.
|
protected void |
before(StructuredFormatter.Generator generator,
ExtLogRecord record)
Invoked before the structured data is added to the generator.
|
protected abstract StructuredFormatter.Generator |
createGenerator(Writer writer)
Creates the generator used to create the structured data.
|
String |
format(ExtLogRecord record)
Format a message using an extended log record.
|
DateTimeFormatter |
getDateTimeFormatter()
Returns the current formatter used to format a records date and time.
|
StructuredFormatter.ExceptionOutputType |
getExceptionOutputType()
Get the current output type for exceptions.
|
protected String |
getKey(StructuredFormatter.Key defaultKey)
Checks to see if the key should be overridden.
|
String |
getKeyOverrides()
A string representation of the key overrides.
|
String |
getMetaData()
Returns the value set for meta data.
|
String |
getRecordDelimiter()
Returns the character used to indicate the record has is complete.
|
ZoneId |
getZoneId()
Returns the current zone id used for the date and time formatter.
|
boolean |
isCallerCalculationRequired()
Determines whether or not this formatter will require caller, source level, information when a log record is
formatted.
|
protected boolean |
isDetailedExceptionOutputType()
Checks the exception output type and determines if detailed output should be written.
|
protected boolean |
isFormattedExceptionOutputType()
Checks the exception output type and determines if formatted output should be written.
|
boolean |
isPrintDetails()
Indicates whether or not details should be printed.
|
void |
setDateFormat(String pattern)
Sets the pattern to use when formatting the date.
|
void |
setExceptionOutputType(StructuredFormatter.ExceptionOutputType exceptionOutputType)
Set the output type for exceptions.
|
void |
setMetaData(String metaData)
Sets the meta data to use in the structured format.
|
void |
setPrintDetails(boolean printDetails)
Sets whether or not details should be printed.
|
void |
setRecordDelimiter(String eorDelimiter)
Sets the value to be used to indicate the end of a record.
|
void |
setZoneId(String zoneId)
|
format
formatMessage, getHead, getTail
protected StructuredFormatter()
protected StructuredFormatter(Map<StructuredFormatter.Key,String> keyOverrides)
protected StructuredFormatter(String keyOverrides)
protected abstract StructuredFormatter.Generator createGenerator(Writer writer) throws Exception
Exception
- if an error occurs creating the generatorprotected void before(StructuredFormatter.Generator generator, ExtLogRecord record) throws Exception
generator
- the generator to userecord
- the log recordException
protected void after(StructuredFormatter.Generator generator, ExtLogRecord record) throws Exception
generator
- the generator to userecord
- the log recordException
protected final String getKey(StructuredFormatter.Key defaultKey)
defaultKey
- the default keypublic final String format(ExtLogRecord record)
ExtFormatter
format
in class ExtFormatter
record
- the log recordpublic boolean isCallerCalculationRequired()
ExtFormatter
isCallerCalculationRequired
in class ExtFormatter
true
if the formatter will need caller information, otherwise false
LogRecord.getSourceClassName()
,
ExtLogRecord.getSourceFileName()
,
ExtLogRecord.getSourceLineNumber()
,
LogRecord.getSourceMethodName()
public String getKeyOverrides()
null
.null
if no overrides were configuredpublic String getRecordDelimiter()
\n
and may be
null
if no end of record character is desired.null
if no delimiter is desiredpublic void setRecordDelimiter(String eorDelimiter)
null
no delimiter will be used at
the end of the record.eorDelimiter
- the delimiter to be used or null
to not use a delimiterpublic String getMetaData()
The value is a string where key/value pairs are separated by commas. The key and value are separated by an equal sign.
null
if one was not setPropertyValues.stringToMap(String)
public void setMetaData(String metaData)
The value is a string where key/value pairs are separated by commas. The key and value are separated by an equal sign.
metaData
- the meta data to set or null
to not format any meta dataPropertyValues.stringToMap(String)
public DateTimeFormatter getDateTimeFormatter()
public void setDateFormat(String pattern)
DateTimeFormatter.ofPattern(String)
pattern.
If the pattern is null
a 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.
pattern
- the pattern to use or null
to use a default patternpublic ZoneId getZoneId()
public void setZoneId(String zoneId)
ZoneId
to use when formatting the date and time from the LogRecord
.
The rules of the id must conform to the rules specified on ZoneId.of(String)
.
zoneId
- the zone id or null
to use the system defaultZoneId.of(String)
public boolean isPrintDetails()
true
if details should be printed, otherwise false
public void setPrintDetails(boolean printDetails)
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.
printDetails
- true
if details should be printedpublic StructuredFormatter.ExceptionOutputType getExceptionOutputType()
public void setExceptionOutputType(StructuredFormatter.ExceptionOutputType exceptionOutputType)
DETAILED
.exceptionOutputType
- the desired output type, if null
StructuredFormatter.ExceptionOutputType.DETAILED
is usedprotected boolean isDetailedExceptionOutputType()
true
if detailed output should be written, otherwise false
protected boolean isFormattedExceptionOutputType()
Throwable.printStackTrace()
.true
if formatted exception output should be written, otherwise false
Copyright © 2021 JBoss by Red Hat. All rights reserved.