Package net.logstash.logback.composite
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
DateTimeFormatter
pattern - A string value representing the number of milliseconds since unix epoch (designated by specifying the pattern value as "[UNIX_TIMESTAMP_AS_STRING]")
- A number value of the milliseconds since unix epoch (designated by specifying the pattern value as "[UNIX_TIMESTAMP_AS_NUMBER]")
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Writes the timestamp to the JsonGenerator as a number of milliseconds since unix epoch.protected static class
Writes the timestamp to the JsonGenerator as a string, converting the timestamp millis into a String using the supplied Function.protected static interface
Writes the timestamp to the JsonGenerator -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Keyword used bysetTimeZone(String)
to denote the system default time zone.static final String
static final String
Setting thepattern
as this value will make it so that the timestamp is written as a number value of the milliseconds since unix epoch.static final String
Setting thepattern
as 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 ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
getFormattedTimestamp
(Event event) protected abstract Instant
getTimestampAsInstant
(Event event) Get the time zone used to write the timestamp.void
setFieldNames
(FieldNames fieldNames) void
setPattern
(String pattern) void
setTimeZone
(String timeZone) Set the timezone for which to write the timestamp.void
writeTo
(JsonGenerator generator, Event event) Writes information about the event, to the given generator.Methods inherited from class net.logstash.logback.composite.AbstractFieldJsonProvider
getFieldName, setFieldName
Methods inherited from class net.logstash.logback.composite.AbstractJsonProvider
assertIsStarted, isStarted, prepareForDeferredProcessing, start, 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
-
Field Details
-
FIELD_TIMESTAMP
- See Also:
-
UNIX_TIMESTAMP_AS_NUMBER
Setting thepattern
as 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 thepattern
as 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:
setFieldNames
in interfaceFieldNamesAware<Event extends DeferredProcessingAware>
-
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
-
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]" or "[UNIX_TIMESTAMP_AS_STRING]".The value of the
timeZone
can be any string accepted by java'sTimeZone.getTimeZone(String)
method. For example "America/Los_Angeles" or "GMT+10".Use a blank string,
null
or the value "[DEFAULT]" 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
-