Interface LogFormatter.TimestampFormatter
- All Superinterfaces:
LogFormatter
- All Known Implementing Classes:
LogFormatter.NoopFormatter
- Enclosing interface:
LogFormatter
public static sealed interface LogFormatter.TimestampFormatter
extends LogFormatter
permits LogFormatter.NoopFormatter (not exhaustive)
Formats event timestamps.
-
Nested Class Summary
Nested classes/interfaces inherited from interface LogFormatter
LogFormatter.Builder, LogFormatter.EventFormatter, LogFormatter.KeyValueNullStrategy, LogFormatter.LevelFormatter, LogFormatter.NoopFormatter, LogFormatter.StaticFormatter, LogFormatter.ThrowableFormatter, LogFormatter.TimestampFormatterModifier and TypeInterfaceDescriptionstatic final classLog formatter builder that is composed of other formatters.static interfaceGeneric event formatting that is lambda friendly.static enumControls how anullkey value is handled by formatters that print a selected subset of keys (e.g.static interfaceFormats aSystem.Logger.Level.static enumA special formatter that will do nothing.static final recordA special formatter that will append static text.static interfaceFormats a throwable.static interfaceFormats event timestamps. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default timestamp format used in many logging frameworks which does not have dates and only time at millisecond precision. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidformat(StringBuilder output, LogEvent event) Formats a log event.voidformatTimestamp(StringBuilder output, Instant instant) Format timestamp.of()Formats timestamp usingTTLL_TIME_FORMAT.of(DateTimeFormatter dateTimeFormatter) Formats a timestamp using standard JDK date time formatter.of(DateTimeFormatter dateTimeFormatter, boolean cacheMillisecondPrecision) Formats a timestamp using standard JDK date time formatter.ofISO()Formats a timestamp using ISO format at fixed millisecond precision (e.g.ofMicros()Micro seconds over the events last second.Methods inherited from interface LogFormatter
isNoopModifier and TypeMethodDescriptiondefault booleanisNoop()Ask the formatter if will do anything.
-
Field Details
-
TTLL_TIME_FORMAT
The default timestamp format used in many logging frameworks which does not have dates and only time at millisecond precision.It is called TTLL as that is the name of the format where it is used in logback, log4j etc.
- See Also:
-
-
Method Details
-
formatTimestamp
Format timestamp.- Parameters:
output- buffer.instant- timestamp.
-
format
Description copied from interface:LogFormatterFormats a log event.- Specified by:
formatin interfaceLogFormatter- Parameters:
output- buffer.event- log event.- See Also:
-
of
Formats timestamp usingTTLL_TIME_FORMAT.- Returns:
- formatter.
-
ofISO
Formats a timestamp using ISO format at fixed millisecond precision (e.g.2023-11-14T22:13:20.123Z, always exactly 3 fractional digits). Pair withofMicros()to append additional sub-millisecond digits, similar to Logback's%d{ISO8601}%microsecond.- Returns:
- formatter.
-
ofMicros
Micro seconds over the events last second. This is for logback compatibility.- Returns:
- microseconds zero padded.
-
of
Formats a timestamp using standard JDK date time formatter.- Parameters:
dateTimeFormatter- date time formatter.- Returns:
- timestamp formatter.
-
of
static LogFormatter.TimestampFormatter of(DateTimeFormatter dateTimeFormatter, boolean cacheMillisecondPrecision) Formats a timestamp using standard JDK date time formatter.Formatting with
DateTimeFormatteris comparatively expensive to do on every event, so if the caller knows the formatter's finest resolution is milliseconds (e.g. a pattern using at mostSSS, nevern/Nnanosecond fields),cacheMillisecondPrecisioncan be set totrueto reuse the previously formatted string whenever consecutive events land in the same millisecond - the same trick Logback'sCachingDateFormatterand Log4j2'sFixedDateFormatuse. Passingtruefor a formatter that can actually render sub-millisecond precision will silently truncate that precision, so only passtruewhen the pattern is known to not exceed millisecond resolution.- Parameters:
dateTimeFormatter- date time formatter.cacheMillisecondPrecision-trueif the formatter's output is fully determined by the instant's millisecond value.- Returns:
- timestamp formatter.
-