java.lang.Object
org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver
All Implemented Interfaces:
EventResolver, TemplateResolver<LogEvent>

public final class TimestampResolver extends Object implements EventResolver
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