Skip to content

Commit

Permalink
fix: timestampNanos nanos precision.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-dudek committed Jul 6, 2023
1 parent 186a150 commit 1549643
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected Map<String, Object> toJsonMap(ILoggingEvent event) {
TimeUnit.MILLISECONDS.toSeconds(event.getTimeStamp()));
map.put(
StackdriverTraceConstants.TIMESTAMP_NANOS_ATTRIBUTE,
TimeUnit.MILLISECONDS.toNanos(event.getTimeStamp() % 1_000));
event.getNanoseconds());
}

add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,22 @@ void testJsonSeverityLevelMapping() {
.containsExactly("DEBUG", "DEBUG", "INFO", "WARNING", "ERROR", "ERROR");
}

@Test
void testTimestampNanos() {
LOGGER.warn("test1");
LOGGER.warn("test2");

List<String> jsonLogRecords = Arrays.asList(new String(logOutput.toByteArray()).split("\n"));

List<Double> logTimestampNanos =
jsonLogRecords.stream()
.map(record -> GSON.fromJson(record, Map.class))
.map(data -> (Double)data.get(StackdriverTraceConstants.TIMESTAMP_NANOS_ATTRIBUTE))
.collect(Collectors.toList());

assertThat(logTimestampNanos).anyMatch(nanos -> nanos % 1000000 > 0);
}

@Test
void testJsonLayoutEnhancer_missing() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
Expand Down

0 comments on commit 1549643

Please sign in to comment.