diff --git a/core/src/main/java/com/linecorp/armeria/internal/common/logging/LoggingDecorators.java b/core/src/main/java/com/linecorp/armeria/internal/common/logging/LoggingDecorators.java index 5469d7eb7307..30eb840889a0 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/common/logging/LoggingDecorators.java +++ b/core/src/main/java/com/linecorp/armeria/internal/common/logging/LoggingDecorators.java @@ -52,22 +52,21 @@ public static void logWhenComplete( Logger logger, RequestContext ctx, Consumer requestLogger, Consumer responseLogger) { final boolean isTransientService = isTransientService(ctx); - final CompletableFuture requestCompletionFuture = ctx.log().whenRequestComplete(); + final CompletableFuture requestCompletionFuture; if (!isTransientService) { - requestCompletionFuture.thenAccept(requestLogger).exceptionally(e -> { - try (SafeCloseable ignored = ctx.push()) { - logger.warn("{} Unexpected exception while logging request: ", ctx, e); - } - return null; + requestCompletionFuture = ctx.log().whenRequestComplete().thenApply(log -> { + requestLogger.accept(log); + return log; }); } else { - requestCompletionFuture.exceptionally(e -> { - try (SafeCloseable ignored = ctx.push()) { - logger.warn("{} Unexpected exception while logging request: ", ctx, e); - } - return null; - }); + requestCompletionFuture = ctx.log().whenRequestComplete(); } + requestCompletionFuture.exceptionally(e -> { + try (SafeCloseable ignored = ctx.push()) { + logger.warn("{} Unexpected exception while logging request: ", ctx, e); + } + return null; + }); ctx.log().whenComplete().thenAccept(responseLogger).exceptionally(e -> { try (SafeCloseable ignored = ctx.push()) { logger.warn("{} Unexpected exception while logging response: ", ctx, e);