Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Timestamp with nanosecond precision (logback 1.3.0) #829

Closed
brenuart opened this issue Aug 9, 2022 · 1 comment · Fixed by #833
Closed

Add support for Timestamp with nanosecond precision (logback 1.3.0) #829

brenuart opened this issue Aug 9, 2022 · 1 comment · Fixed by #833
Assignees
Labels
type/enhancement warn/behavior-change Breaking change of publicly advertised behavior
Milestone

Comments

@brenuart
Copy link
Collaborator

brenuart commented Aug 9, 2022

Starting from 1.3.0-alpha12, Logback events are now storing timestamp with nanosecond precision (using an Instant). The AbstractTimestampJsonProvider should be updated to take this enhancement into account.

(1) Backward compatibility

A new getInstant() method has been added to LoggingEvent in version 1.3.0 which was not available in previous versions. The implementation should make use of reflection to detect at runtime if the getInstant() method is available and automatically enable nanosecond precision in our JsonProvider.

It should be noted that as of version 1.3.0-beta0 AccessEvents have not (yet) been enhanced with a getInstant() method and therefore lack nanosecond precision. Using the above mentioned strategy should help us to keep using the current AbstractFormattedTimestampJsonProvider as a base class for both the LoggingEvent and AccessEvent specialisations: getInstant() not available on AccessEvent -> nanosecond not enabled -> revert to millis as currently.

(2) Available timestamp formats and default

By default timestamps are formatted as [ISO_OFFSET_DATE_TIME]. As per the javadoc of java.time.format.DateTimeFormatter this format outputs nanoseconds but drops the insignificant leading zeros. This means that:

  • precision will be at most three digits (milliseconds) when used with logback 1.2
  • precision will be up to 9 digits (nanoseconds) when used with logback 1.3
    Users should be aware they will suddenly have a higher timestamp precision just by upgrading the logback and LLE versions while keeping the same configuration. If nanosecond precision is not desired, users have the option of configuring an explicit format pattern instead of using the [ISO_OFFSET_DATE_TIME] keyword.

[UNIX_TIMESTAMP_AS_NUMBER] and [UNIX_TIMESTAMP_AS_STRING] will behave asis.

@brenuart
Copy link
Collaborator Author

brenuart commented Aug 9, 2022

@philsttr What's your opinion? Any feedback?

@brenuart brenuart changed the title Timestamp with nanosecond precision (logback 1.3.0) Add support for Timestamp with nanosecond precision (logback 1.3.0) Aug 9, 2022
@brenuart brenuart added this to the 7.3 milestone Aug 14, 2022
@brenuart brenuart self-assigned this Aug 14, 2022
brenuart added a commit that referenced this issue Aug 14, 2022
* Detect at runtime which version of Logback ins used.
If version 1.3, get timestamp by calling the new  `ILoggingEvent#getInstant()` method which provides nanoseconds precision.
If version before 1.3, get the timestamp by calling the older `IloggingEvent#getTimeStamp()` method which gives only milliseconds precision.

* Use an Instant internally whatever version of Logback is used. Adapt TimestampJsonProvider and the associated FastIOSTimestampFormatter to accept Instant with nano precision instead of a long millis.

* Add some words about nanos in README.md

closes #829
@philsttr philsttr added the warn/behavior-change Breaking change of publicly advertised behavior label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement warn/behavior-change Breaking change of publicly advertised behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants