Class TimestampResolver
java.lang.Object
org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver
- All Implemented Interfaces:
EventResolver,TemplateResolver<LogEvent>
Timestamp resolver.
Configuration
config = [ patternConfig | epochConfig ]
patternConfig = "pattern" -> ( [ format ] , [ timeZone ] , [ locale ] )
format = "format" -> string
timeZone = "timeZone" -> string
locale = "locale" -> (
language |
( language , "_" , country ) |
( language , "_" , country , "_" , variant )
)
epochConfig = "epoch" -> ( unit , [ rounded ] )
unit = "unit" -> (
"nanos" |
"millis" |
"secs" |
"millis.nanos" |
"secs.nanos" |
)
rounded = "rounded" -> boolean
If no configuration options are provided, pattern-config is
employed. There JsonTemplateLayoutDefaults.getTimestampFormatPattern(), JsonTemplateLayoutDefaults.getTimeZone(), JsonTemplateLayoutDefaults.getLocale() are used as defaults for
pattern, timeZone, and locale, respectively.
In epoch-config, millis.nanos, secs.nanos stand
for the fractional component in nanoseconds.
Examples
| Configuration | Output |
{
"$resolver": "timestamp"
}
|
2020-02-07T13:38:47.098+02:00
|
{
"$resolver": "timestamp",
"pattern": {
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"timeZone": "UTC",
"locale": "en_US"
}
}
|
2020-02-07T13:38:47.098Z
|
{
"$resolver": "timestamp",
"epoch": {
"unit": "secs"
}
}
|
1581082727.982123456
|
{
"$resolver": "timestamp",
"epoch": {
"unit": "secs",
"rounded": true
}
}
|
1581082727
|
{
"$resolver": "timestamp",
"epoch": {
"unit": "secs.nanos"
}
}
|
982123456
|
{
"$resolver": "timestamp",
"epoch": {
"unit": "millis"
}
}
|
1581082727982.123456
|
{
"$resolver": "timestamp",
"epoch": {
"unit": "millis",
"rounded": true
}
}
|
1581082727982
|
{
"$resolver": "timestamp",
"epoch": {
"unit": "millis.nanos"
}
}
|
123456
|
{
"$resolver": "timestamp",
"epoch": {
"unit": "nanos"
}
}
|
1581082727982123456
|
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static classprivate static final classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final EventResolverprivate static final EventResolverprivate static final EventResolverprivate static final EventResolverprivate static final EventResolverprivate static final EventResolverprivate static final EventResolverprivate final EventResolver -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static EventResolverprivate static EventResolverprivate static EventResolvercreateResolver(TemplateResolverConfig config) private static longepochNanos(Instant instant) (package private) static StringgetName()voidresolve(LogEvent logEvent, JsonWriter jsonWriter) Resolves the givenvalueusing the providedJsonWriter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.logging.log4j.layout.template.json.resolver.TemplateResolver
isFlattening, isResolvable, isResolvable, resolve
-
Field Details
-
internalResolver
-
EPOCH_NANOS_RESOLVER
-
EPOCH_MILLIS_RESOLVER
-
EPOCH_MILLIS_ROUNDED_RESOLVER
-
EPOCH_MILLIS_NANOS_RESOLVER
-
EPOCH_SECS_RESOLVER
-
EPOCH_SECS_ROUNDED_RESOLVER
-
EPOCH_SECS_NANOS_RESOLVER
-
-
Constructor Details
-
TimestampResolver
TimestampResolver(TemplateResolverConfig config)
-
-
Method Details
-
createResolver
-
createPatternResolver
-
createEpochResolver
-
epochNanos
-
getName
-
resolve
Description copied from interface:TemplateResolverResolves the givenvalueusing the providedJsonWriter.- Specified by:
resolvein interfaceTemplateResolver<LogEvent>
-