Top Description Inners Fields Constructors Methods
org.jboss.logmanager.formatters

public Class JsonFormatter

extends StructuredFormatter
Class Inheritance
Annotations
@SuppressWarnings:unused, WeakerAccess
Imports
java.io.Writer, java.math.BigDecimal, .BigInteger, java.util.HashMap, .Map, jakarta.json.Json, .JsonValue, jakarta.json.stream.JsonGenerator, .JsonGeneratorFactory, org.jboss.logmanager.PropertyValues

A formatter that outputs the record into JSON format optionally printing details.

Note that including details can be expensive in terms of calculating the caller.

The details include;

Author
James R. Perkins

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
private JsonGeneratorFactory

Constructor Summary

AccessConstructor and Description
public
JsonFormatter()

Creates a new JSON formatter.

public
JsonFormatter(final String
a string representation of a map to override keys
keyOverrides
)

Creates a new JSON formatter.

public
JsonFormatter(final Map<StructuredFormatter.Key, String>
a map of overrides for the default keys
keyOverrides
)

Creates a new JSON formatter.

Method Summary

Modifier and TypeMethod and Description
protected StructuredFormatter.Generator
createGenerator(final Writer writer)

Implements abstract org.jboss.logmanager.formatters.StructuredFormatter.createGenerator.

Creates the generator used to create the structured data.

public boolean

Returns:

true if pretty printing is enabled, otherwise false
isPrettyPrint
()

Indicates whether or not pretty printing is enabled.

public void
setPrettyPrint(final boolean
true to turn on pretty printing or false to turn it off
prettyPrint
)

Turns on or off pretty printing.

Inherited from org.jboss.logmanager.formatters.StructuredFormatter:
afterbeforeformatgetDateTimeFormattergetExceptionOutputTypegetKeygetKeyOverridesgetMetaDatagetRecordDelimitergetZoneIdisCallerCalculationRequiredisDetailedExceptionOutputTypeisFormattedExceptionOutputTypeisPrintDetailssetDateFormatsetExceptionOutputTypesetMetaDatasetPrintDetailssetRecordDelimitersetZoneId

Field Detail

configback to summary
private final Map<String, Object> config
factoryback to summary
private JsonGeneratorFactory factory

Constructor Detail

JsonFormatterback to summary
public JsonFormatter()

Creates a new JSON formatter.

JsonFormatterback to summary
public JsonFormatter(final String keyOverrides)

Creates a new JSON formatter.

Parameters
keyOverrides:String

a string representation of a map to override keys

See Also
PropertyValues#stringToEnumMap(Class, String)
JsonFormatterback to summary
public JsonFormatter(final Map<StructuredFormatter.Key, String> keyOverrides)

Creates a new JSON formatter.

Parameters
keyOverrides:Map<StructuredFormatter.Key, String>

a map of overrides for the default keys

Method Detail

createGeneratorback to summary
protected StructuredFormatter.Generator createGenerator(final Writer writer)

Implements abstract org.jboss.logmanager.formatters.StructuredFormatter.createGenerator.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.createGenerator.

Creates the generator used to create the structured data.

Returns:StructuredFormatter.Generator

the generator to use

Annotations
@Override
isPrettyPrintback to summary
public boolean isPrettyPrint()

Indicates whether or not pretty printing is enabled.

Returns:boolean

true if pretty printing is enabled, otherwise false

setPrettyPrintback to summary
public void setPrettyPrint(final boolean prettyPrint)

Turns on or off pretty printing.

Parameters
prettyPrint:boolean

true to turn on pretty printing or false to turn it off

org.jboss.logmanager.formatters back to summary

private Class JsonFormatter.FormatterJsonGenerator

extends Object
implements Generator
Class Inheritance
  • java.lang.Object
  • org.jboss.logmanager.formatters.JsonFormatter.FormatterJsonGenerator
All Implemented Interfaces
org.jboss.logmanager.formatters.StructuredFormatter.Generator

Field Summary

Modifier and TypeField and Description
private final JsonGenerator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public StructuredFormatter.Generator
add(final String
they key
key
,
final int
the value
value
)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes an integer value.

public StructuredFormatter.Generator
add(final String
they key
key
,
final long
the value
value
)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a long value.

public StructuredFormatter.Generator
add(final String
the key for the map
key
,
final Map<String, ?>
the map
value
)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a map value

public StructuredFormatter.Generator
add(final String
the key for the value
key
,
final String
the string value
value
)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a string value.

public StructuredFormatter.Generator
begin()

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.begin.

Initial method invoked at the start of the generation.

public StructuredFormatter.Generator
end()

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.end.

Writes any trailing data that's needed.

public StructuredFormatter.Generator
public StructuredFormatter.Generator
public StructuredFormatter.Generator
startArray(final String
they key for the array
key
)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.startArray.

Writes the start of an array.

public StructuredFormatter.Generator
startObject(final String
they key for the object, or null if this object was started in an array and the wrapArrays() is false
key
)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.startObject.

Writes the start of an object.

private void
writeObject(final String key, final Object obj)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

generatorback to summary
private final JsonGenerator generator

Constructor Detail

FormatterJsonGeneratorback to summary
private FormatterJsonGenerator(final JsonGenerator generator)

Method Detail

addback to summary
public StructuredFormatter.Generator add(final String key, final int value)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes an integer value.

Parameters
key:String

they key

value:int

the value

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
addback to summary
public StructuredFormatter.Generator add(final String key, final long value)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a long value.

Parameters
key:String

they key

value:long

the value

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
addback to summary
public StructuredFormatter.Generator add(final String key, final Map<String, ?> value)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a map value

Parameters
key:String

the key for the map

value:Map<String, ?>

the map

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
addback to summary
public StructuredFormatter.Generator add(final String key, final String value)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a string value.

Parameters
key:String

the key for the value

value:String

the string value

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
beginback to summary
public StructuredFormatter.Generator begin()

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.begin.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.begin.

Initial method invoked at the start of the generation.

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
endback to summary
public StructuredFormatter.Generator end()

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.end.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.end.

Writes any trailing data that's needed.

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
endArrayback to summary
public StructuredFormatter.Generator endArray() throws Exception

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.endArray.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.endArray.

Writes an end for an array. This defaults to endObject() for convenience of generators that don't have a specific type for arrays.

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
endObjectback to summary
public StructuredFormatter.Generator endObject() throws Exception

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.endObject.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.endObject.

Writes an end to the object.

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
startArrayback to summary
public StructuredFormatter.Generator startArray(final String key) throws Exception

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.startArray.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.startArray.

Writes the start of an array. This defaults to startObject(String) for convenience of generators that don't have a specific type for arrays.

Parameters
key:String

they key for the array

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
startObjectback to summary
public StructuredFormatter.Generator startObject(final String key) throws Exception

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.startObject.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.startObject.

Writes the start of an object.

If the wrapArrays() returns false the key may be null and implementations should handle this.

Parameters
key:String

they key for the object, or null if this object was started in an array and the wrapArrays() is false

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
writeObjectback to summary
private void writeObject(final String key, final Object obj)