Class AbstractFormattedTimestampJsonProvider<Event extends DeferredProcessingAware, FieldNames extends LogstashCommonFieldNames>
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
net.logstash.logback.composite.AbstractJsonProvider<Event>
net.logstash.logback.composite.AbstractFieldJsonProvider<Event>
net.logstash.logback.composite.AbstractFormattedTimestampJsonProvider<Event, FieldNames>
- All Implemented Interfaces:
ContextAware, FieldNamesAware<FieldNames>, JsonProvider<Event>
- Direct Known Subclasses:
AccessEventFormattedTimestampJsonProvider, FormattedTimestampJsonProvider, LoggingEventFormattedTimestampJsonProvider
public abstract class AbstractFormattedTimestampJsonProvider<Event extends DeferredProcessingAware, FieldNames extends LogstashCommonFieldNames>
extends AbstractFieldJsonProvider<Event>
implements FieldNamesAware<FieldNames>
Writes the timestamp field as either:
- A string value formatted by a
DateTimeFormatterpattern - A string value representing the number of milliseconds since unix epoch (designated by specifying the pattern value as "[UNIX_TIMESTAMP_AS_STRING]"<Event extends DeferredProcessingAware, FieldNames extends LogstashCommonFieldNames>)
- A number value of the milliseconds since unix epoch (designated by specifying the pattern value as "[UNIX_TIMESTAMP_AS_NUMBER]"<Event extends DeferredProcessingAware, FieldNames extends LogstashCommonFieldNames>)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classWrites the timestamp to the JsonGenerator as a number of milliseconds since unix epoch.protected static classWrites the timestamp to the JsonGenerator as a string, converting the timestamp millis into a String using the supplied Function.protected static interfaceWrites the timestamp to the JsonGenerator -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKeyword used bysetTimeZone(String)to denote the system default time zone.static final Stringstatic final StringSetting thepatternas this value will make it so that the timestamp is written as a number value of the milliseconds since unix epoch.static final StringSetting thepatternas this value will make it so that the timestamp is written as a string value representing the number of milliseconds since unix epochFields inherited from class ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringgetFormattedTimestamp(Event event) protected abstract InstantgetTimestampAsInstant(Event event) Get the time zone used to write the timestamp.voidsetFieldNames(FieldNames fieldNames) voidsetPattern(String pattern) voidsetTimeZone(String timeZone) Set the timezone for which to write the timestamp.voidwriteTo(JsonGenerator generator, Event event) Writes information about the event, to the given generator.Methods inherited from class AbstractFieldJsonProvider
getFieldName, setFieldNameMethods inherited from class AbstractJsonProvider
assertIsStarted, isStarted, prepareForDeferredProcessing, start, stopMethods inherited from class ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
FIELD_TIMESTAMP
- See Also:
-
UNIX_TIMESTAMP_AS_NUMBER
Setting thepatternas this value will make it so that the timestamp is written as a number value of the milliseconds since unix epoch.- See Also:
-
UNIX_TIMESTAMP_AS_STRING
Setting thepatternas this value will make it so that the timestamp is written as a string value representing the number of milliseconds since unix epoch- See Also:
-
DEFAULT_TIMEZONE_KEYWORD
Keyword used bysetTimeZone(String)to denote the system default time zone.- See Also:
-
-
Constructor Details
-
AbstractFormattedTimestampJsonProvider
public AbstractFormattedTimestampJsonProvider()
-
-
Method Details
-
setFieldNames
- Specified by:
setFieldNamesin interfaceFieldNamesAware<Event extends DeferredProcessingAware>
-
writeTo
Description copied from interface:JsonProviderWrites 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:
writeToin interfaceJsonProvider<Event extends DeferredProcessingAware>- Parameters:
generator- theJsonGeneratorto produce JSON contentevent- the event to convert into JSON
-
getFormattedTimestamp
-
getTimestampAsInstant
-
getPattern
-
setPattern
-
getTimeZone
Get the time zone used to write the timestamp.- Returns:
- the time zone used to write the timestamp
-
setTimeZone
Set the timezone for which to write the timestamp. Only applicable if the pattern is not "[UNIX_TIMESTAMP_AS_NUMBER]"<Event extends DeferredProcessingAware, FieldNames extends LogstashCommonFieldNames> or "[UNIX_TIMESTAMP_AS_STRING]"<Event extends DeferredProcessingAware, FieldNames extends LogstashCommonFieldNames>.The value of the
timeZonecan be any string accepted by java'sTimeZone.getTimeZone(String)method. For example "America/Los_Angeles" or "GMT+10".Use a blank string,
nullor the value "[DEFAULT]"<Event extends DeferredProcessingAware, FieldNames extends LogstashCommonFieldNames> to use the default TimeZone of the system.- Parameters:
timeZone- the textual representation of the desired time zone- Throws:
IllegalArgumentException- if the input string is not a valid TimeZone representation
-