Skip to content

provide a %date{EPOCH_SECONDS} to get the date printed as seconds from epoch #968

@ghost

Description

The documentation at https://logback.qos.ch/manual/layouts.html

Currently it seems there is no way to get the epoch seconds, it delegates to java.time.format.DateTimeFormatter and that has no way to print the seconds from the epoch.

I think it would be useful to provide

  • %date{EPOCH_SECONDS} like 1758543352 (integer, non fractional , no float) (Monday, September 22, 2025 12:15:52.005 PM losing the milliseconds)
  • %date{EPOCH_MILLIS} like 1758543352005 (Monday, September 22, 2025 12:15:52.005 PM)

This those two it will be possible to use %date{EPOCH_SECONDS}.%date{n} to get 1758543352.005999999 etc.

For example I'm trying to use logstash-logback-encoder to get two fields in JSON timestampSeconds and timestampNanos to produce structured logs that are compliant with that the google logging agent expects ( Logging agent: special JSON fields and Time-related fields), I can get the timestampNanos from %date{n} but I can't get the value for timestampSeconds from logback.

       <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <timestamp />
                <pattern>
                    <pattern>
                        {
                        "timestampSeconds": "%date{EPOCH_SECONDS}",
                        "timestampNanos":"%date{n}"
                        }
                    </pattern>
                </pattern>
                <logLevel>
                    <fieldName>severity</fieldName>
                </logLevel>

                <loggerName />
                <message />
                <mdc />
                <stackTrace />
            </providers>
        </encoder>

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions