-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
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}like1758543352(integer, non fractional , no float) (Monday, September 22, 2025 12:15:52.005 PMlosing the milliseconds)%date{EPOCH_MILLIS}like1758543352005(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>
Reactions are currently unavailable