public final class TimestampResolver extends Object implements EventResolver
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" -> booleanIf 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.
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 |
Modifier and Type | Method and Description |
---|---|
void |
resolve(LogEvent logEvent,
JsonWriter jsonWriter)
Resolves the given
value using the provided JsonWriter . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isFlattening, isResolvable, isResolvable, resolve
public void resolve(LogEvent logEvent, JsonWriter jsonWriter)
TemplateResolver
value
using the provided JsonWriter
.resolve
in interface TemplateResolver<LogEvent>
Copyright © 1999-2022 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.