From 0e00417a2c6623daa0b1723a15cac9a56de57fe7 Mon Sep 17 00:00:00 2001 From: hexoul Date: Fri, 14 May 2021 12:47:09 +0900 Subject: [PATCH] Address comments --- .../common/logging/LoggingDecorators.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) 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 5469d7eb730..30eb840889a 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);