diff --git a/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestClientLogInterceptor.java b/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestClientLogInterceptor.java index 7070b4f..650c842 100644 --- a/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestClientLogInterceptor.java +++ b/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestClientLogInterceptor.java @@ -92,16 +92,16 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re context.close(); if (config.client.end.mdc.enabled) { - MDC.put(config.client.end.mdc.durationName, context.time); + MDC.put(config.client.end.mdc.durationName, context.durationSec); context.mdcKeys.add(config.client.end.mdc.durationName); MDC.put(config.client.end.mdc.responseStatusName, status.getStatusCode()); - context.mdcKeys.add(config.end.mdc.responseStatusName); + context.mdcKeys.add(config.client.end.mdc.responseStatusName); } if (config.client.end.enabled) { log.info(String.format(config.client.end.template, context.method, context.uri, - context.time, status.getStatusCode(), status.getReasonPhrase())); + context.durationString, status.getStatusCode(), status.getReasonPhrase())); } } finally { // clean up MDC header keys diff --git a/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestInterceptorContext.java b/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestInterceptorContext.java index fa0abbf..f638579 100644 --- a/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestInterceptorContext.java +++ b/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestInterceptorContext.java @@ -1,5 +1,7 @@ package org.tkit.quarkus.log.rs; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.HashSet; import java.util.Set; @@ -13,19 +15,25 @@ public class RestInterceptorContext { String path; - String time; - boolean exclude = false; Set mdcKeys = new HashSet<>(); private final long startTime; + long durationMillis; + + double durationSec; + + String durationString; + RestInterceptorContext() { this.startTime = System.currentTimeMillis(); } public void close() { - time = String.format("%.3f", (System.currentTimeMillis() - startTime) / 1000f); + durationMillis = (System.currentTimeMillis() - startTime); + durationSec = BigDecimal.valueOf(durationMillis / 1000f).setScale(3, RoundingMode.HALF_DOWN).doubleValue(); + durationString = String.format("%.3f", durationSec); } } diff --git a/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestLogInterceptor.java b/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestLogInterceptor.java index 7dc7235..9e159a4 100644 --- a/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestLogInterceptor.java +++ b/extensions/log/rs/runtime/src/main/java/org/tkit/quarkus/log/rs/RestLogInterceptor.java @@ -138,7 +138,7 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont Response.StatusType status = responseContext.getStatusInfo(); if (config.end.mdc.enabled) { - MDC.put(config.end.mdc.durationName, restContext.time); + MDC.put(config.end.mdc.durationName, restContext.durationSec); restContext.mdcKeys.add(config.end.mdc.durationName); MDC.put(config.end.mdc.responseStatusName, status.getStatusCode()); @@ -147,7 +147,7 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont LoggerFactory.getLogger(resourceInfo.getResourceClass()) .info(String.format(config.end.template, restContext.method, restContext.path, - restContext.time, status.getStatusCode(), status.getReasonPhrase(), + restContext.durationString, status.getStatusCode(), status.getReasonPhrase(), restContext.uri)); } } finally {