From 9de61edbafcc403512b53841843ecbd6b5cc5971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Kelemen?= Date: Tue, 23 Apr 2024 13:48:38 +0200 Subject: [PATCH 1/2] #600 Requests without request body are not logged by optimzed logger fix --- .../coffee/rest/log/optimized/BaseRestLogger.java | 8 +++++++- docs/en/migration/migration260to270.adoc | 4 +++- docs/hu/migration/migration260to270.adoc | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java b/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java index 17727f922..62ed280ae 100644 --- a/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java +++ b/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; import jakarta.inject.Inject; import jakarta.inject.Named; @@ -111,6 +111,10 @@ protected void processRequest(ContainerRequestContext requestContext) { appendRequestLine(logMessage, requestContext); appendRequestHeaders(logMessage, requestContext); + if (!requestContext.hasEntity() || requestContext.getLength() <= 0) { + log.info(logMessage.toString()); + } + int maxRequestEntityLogSize = requestResponseLogger.getMaxRequestEntityLogSize(requestContext); var requestLoggerInputStream = new RequestLoggerInputStream( @@ -202,6 +206,8 @@ protected void appendRequestHeaders(StringBuilder b, ContainerRequestContext req */ protected void appendRequestLine(StringBuilder b, ContainerRequestContext requestContext) { b.append(requestResponseLogger.printRequestLine(requestContext)); + // Mivel csak a stream végén történik a logolás, a timestamp nem a request beérkezését mutatja + b.append(RequestResponseLogger.REQUEST_PREFIX).append("-- Request timestamp:").append(OffsetDateTime.now()).append('\n'); } /** diff --git a/docs/en/migration/migration260to270.adoc b/docs/en/migration/migration260to270.adoc index e3529d601..081e56497 100644 --- a/docs/en/migration/migration260to270.adoc +++ b/docs/en/migration/migration260to270.adoc @@ -79,9 +79,11 @@ which can throw `hu.icellmobilsoft.coffee.se.api.exception.BaseException`. === coffee-rest -* Tha classes found in the `hu.icellmobilsoft.coffee.rest.exception` package use the new `hu.icellmobilsoft.coffee.se.api.exception.BaseException`. +* The classes found in the `hu.icellmobilsoft.coffee.rest.exception` package use the new `hu.icellmobilsoft.coffee.se.api.exception.BaseException`. Such as `DefaultBaseExceptionMapper`, `DefaultExceptionMessageTranslator`, `DefaultGeneralExceptionMapper` and `IExceptionMessageTranslator`. +* The `hu.icellmobilsoft.coffee.rest.log.optimized.BaseRestLogger` has been improved so the HTTP GET calls are logged now. + ==== Migration * `jakarta.ws.rs.ext.ExceptionMapper` and `hu.icellmobilsoft.coffee.rest.exception.IExceptionMessageTranslator` diff --git a/docs/hu/migration/migration260to270.adoc b/docs/hu/migration/migration260to270.adoc index de0fe3a30..62ca28109 100644 --- a/docs/hu/migration/migration260to270.adoc +++ b/docs/hu/migration/migration260to270.adoc @@ -85,6 +85,8 @@ fgv-t vár, amik dobhatnak `hu.icellmobilsoft.coffee.se.api.exception.BaseExcept `DefaultExceptionMessageTranslator`, `DefaultGeneralExceptionMapper` és `IExceptionMessageTranslator` osztályok már az új `hu.icellmobilsoft.coffee.se.api.exception.BaseException`-el dolgoznak. +* `hu.icellmobilsoft.coffee.rest.log.optimized.BaseRestLogger` javításra került, a HTTP GET kérések is már logolódnak. + ==== Átállás * A `jakarta.ws.rs.ext.ExceptionMapper` és `hu.icellmobilsoft.coffee.rest.exception.IExceptionMessageTranslator` From 0735d0c467b41014f8b04d2b5a2c94807910540b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Kelemen?= Date: Tue, 23 Apr 2024 16:35:18 +0200 Subject: [PATCH 2/2] #600 request timestamp changed to UTC --- .../coffee/rest/log/optimized/BaseRestLogger.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java b/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java index 62ed280ae..ab16b1b0a 100644 --- a/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java +++ b/coffee-rest/src/main/java/hu/icellmobilsoft/coffee/rest/log/optimized/BaseRestLogger.java @@ -21,8 +21,8 @@ import java.io.IOException; import java.io.OutputStream; -import java.time.OffsetDateTime; +import hu.icellmobilsoft.coffee.tool.utils.date.DateUtil; import jakarta.inject.Inject; import jakarta.inject.Named; import jakarta.servlet.http.HttpServletResponse; @@ -207,7 +207,7 @@ protected void appendRequestHeaders(StringBuilder b, ContainerRequestContext req protected void appendRequestLine(StringBuilder b, ContainerRequestContext requestContext) { b.append(requestResponseLogger.printRequestLine(requestContext)); // Mivel csak a stream végén történik a logolás, a timestamp nem a request beérkezését mutatja - b.append(RequestResponseLogger.REQUEST_PREFIX).append("-- Request timestamp:").append(OffsetDateTime.now()).append('\n'); + b.append(RequestResponseLogger.REQUEST_PREFIX).append("-- Request timestamp:").append(DateUtil.nowUTC()).append('\n'); } /**