From 021b2bae56655da39554d5dab1d1cb1111b1e916 Mon Sep 17 00:00:00 2001 From: pricelees Date: Sun, 27 Jul 2025 23:40:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20LoggingFilter=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EB=B0=A9=EC=96=B4=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/roomescape/common/log/LoggingFilter.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/roomescape/common/log/LoggingFilter.kt b/src/main/kotlin/roomescape/common/log/LoggingFilter.kt index ea155306..07a63658 100644 --- a/src/main/kotlin/roomescape/common/log/LoggingFilter.kt +++ b/src/main/kotlin/roomescape/common/log/LoggingFilter.kt @@ -11,6 +11,7 @@ import org.springframework.stereotype.Component import org.springframework.web.filter.OncePerRequestFilter import org.springframework.web.util.ContentCachingRequestWrapper import org.springframework.web.util.ContentCachingResponseWrapper +import java.nio.charset.StandardCharsets private val log = KotlinLogging.logger {} @@ -54,12 +55,20 @@ class LoggingFilter( if (log.isDebugEnabled()) { request.contentAsByteArray.takeIf { it.isNotEmpty() } - ?.let { payload["request_body"] = objectMapper.readValue(it, Map::class.java) } + ?.let { payload["request_body"] = parseContent(it) } response.contentAsByteArray.takeIf { it.isNotEmpty() } - ?.let { payload["response_body"] = objectMapper.readValue(it, Map::class.java) } + ?.let { payload["response_body"] = parseContent(it) } } log.info { objectMapper.writeValueAsString(payload) } } + + private fun parseContent(content: ByteArray): Any { + return try { + objectMapper.readValue(content, Map::class.java) + } catch (_: Exception) { + String(content, StandardCharsets.UTF_8) + } + } }