Package net.logstash.logback.composite
Class GlobalCustomFieldsJsonProvider<Event extends DeferredProcessingAware>
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
net.logstash.logback.composite.AbstractJsonProvider<Event>
net.logstash.logback.composite.GlobalCustomFieldsJsonProvider<Event>
- All Implemented Interfaces:
ContextAware
,JsonFactoryAware
,JsonProvider<Event>
public class GlobalCustomFieldsJsonProvider<Event extends DeferredProcessingAware>
extends AbstractJsonProvider<Event>
implements JsonFactoryAware
-
Field Summary
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
setCustomFields
(String customFields) Set the custom fields as a JSON string.void
setCustomFieldsNode
(JsonNode customFields) Deprecated.void
setCustomFieldsNode
(ObjectNode customFields) Use the fields of the givenObjectNode
(may be empty).void
setJsonFactory
(JsonFactory jsonFactory) void
start()
Start the provider.void
writeTo
(JsonGenerator generator, Event event) Writes information about the event, to the given generator.Methods inherited from class net.logstash.logback.composite.AbstractJsonProvider
assertIsStarted, isStarted, prepareForDeferredProcessing, stop
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Constructor Details
-
GlobalCustomFieldsJsonProvider
public GlobalCustomFieldsJsonProvider()
-
-
Method Details
-
writeTo
Description copied from interface:JsonProvider
Writes information about the event, to the given generator.When called, the generator is assumed to be within a JSON object context (i.e. this provider should write fields and their values to the generator). Upon return, the generator should be within the same JSON object context.
- Specified by:
writeTo
in interfaceJsonProvider<Event extends DeferredProcessingAware>
- Parameters:
generator
- theJsonGenerator
to produce JSON contentevent
- the event to convert into JSON- Throws:
IOException
- if an I/O error occurs
-
start
public void start()Start the provider.The provider is started even when it fails to parse the
customFields
JSON string. An ERROR status is emitted instead and no exception is thrown.- Specified by:
start
in interfaceJsonProvider<Event extends DeferredProcessingAware>
- Overrides:
start
in classAbstractJsonProvider<Event extends DeferredProcessingAware>
-
setCustomFields
Set the custom fields as a JSON string. The string will be parsed when the provider isstart()
.- Parameters:
customFields
- the custom fields as JSON string.
-
getCustomFields
-
getCustomFieldsNode
-
setCustomFieldsNode
Deprecated.usesetCustomFieldsNode(ObjectNode)
instead.Set the custom JSON fields. Must be a valid JsonNode that maps to a JSON object structure, i.e. anObjectNode
.- Parameters:
customFields
- aJsonNode
whose properties must be added as custom fields.- Throws:
IllegalArgumentException
- if the argument is not aObjectNode
.
-
setCustomFieldsNode
Use the fields of the givenObjectNode
(may be empty).- Parameters:
customFields
- the JSON object whose fields as added as custom fields
-
setJsonFactory
- Specified by:
setJsonFactory
in interfaceJsonFactoryAware
-
setCustomFieldsNode(ObjectNode)
instead.