diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt index 02e1cd6..876a7e6 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt @@ -2,7 +2,6 @@ package com.ddd.sonnypolabobe.global.security import com.ddd.sonnypolabobe.global.exception.CustomErrorCode import com.ddd.sonnypolabobe.global.util.DiscordApiClient -import com.ddd.sonnypolabobe.global.util.HttpLog import com.ddd.sonnypolabobe.logger import com.fasterxml.jackson.databind.ObjectMapper import io.jsonwebtoken.JwtException @@ -16,7 +15,6 @@ import org.springframework.web.util.ContentCachingRequestWrapper import org.springframework.web.util.ContentCachingResponseWrapper import org.springframework.web.util.WebUtils import java.io.UnsupportedEncodingException -import java.time.LocalDateTime import java.util.* @@ -42,30 +40,19 @@ class JwtExceptionFilter( val startedAt = System.currentTimeMillis() filterChain.doFilter(requestWrapper, responseWrapper) val endedAt = System.currentTimeMillis() - logger().info( - "\n" + - "[REQUEST] ${request.method} - ${request.requestURI} ${responseWrapper.status} - ${(endedAt - startedAt) / 10000.0} \n" + - "Headers : ${getHeaders(request)} \n" + - "Parameters : ${getRequestParams(request)} \n" + - "Request body : ${getRequestBody(requestWrapper)} \n" + - "Response body : ${getResponseBody(responseWrapper)}" - ) + + val message = "\n" + + "[REQUEST] ${request.method} - ${request.requestURI} ${responseWrapper.status} - ${(endedAt - startedAt) / 10000.0} \n" + + "Headers : ${getHeaders(request)} \n" + + "Parameters : ${getRequestParams(request)} \n" + + "Request body : ${getRequestBody(requestWrapper)} \n" + + "Response body : ${getResponseBody(responseWrapper)}" + logger().error(message) if (responseWrapper.status >= 400 && getResponseBody(responseWrapper).contains( CustomErrorCode.INTERNAL_SERVER_EXCEPTION.message ) ) { - this.discordApiClient.sendErrorLog( - HttpLog( - request.method, - request.requestURI, - responseWrapper.status, - (endedAt - startedAt) / 10000.0, - getHeaders(request), - getRequestParams(request), - getRequestBody(requestWrapper), - getResponseBody(responseWrapper) - ) - ) + this.discordApiClient.sendErrorLog(message) } } } catch (e: JwtException) { diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt index 9f6bcfe..56b317a 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt @@ -1,5 +1,6 @@ package com.ddd.sonnypolabobe.global.util +import com.sun.jndi.ldap.LdapPoolManager.trace import org.springframework.beans.factory.annotation.Value import org.springframework.http.MediaType import org.springframework.http.client.reactive.ReactorClientHttpConnector @@ -22,36 +23,16 @@ class DiscordApiClient( ) .build() - fun sendErrorLog(req: HttpLog) { + fun sendErrorLog(req: String) { val embedData: MutableMap = HashMap() embedData["title"] = "서버 에러 발생" val field1: MutableMap = HashMap() - field1["name"] = "요청 정보" - field1["value"] = req.requestMethod + " " + req.requestURI + " " + req.elapsedTime + "ms" + field1["name"] = "요청" + field1["value"] = req - val field2: MutableMap = HashMap() - field2["name"] = "응답 코드" - field2["value"] = req.responseStatus.toString() - - val field3: MutableMap = HashMap() - field3["name"] = "요청 헤더" - field3["value"] = req.headers.map { it.key + " : " + it.value }.joinToString("\n") - - val field4: MutableMap = HashMap() - field4["name"] = "요청 본문" - field4["value"] = req.requestBody - - val field5: MutableMap = HashMap() - field5["name"] = "요청 파람" - field5["value"] = req.parameters.map { it.key + " : " + it.value }.joinToString("\n") - - val field6: MutableMap = HashMap() - field6["name"] = "응답 본문" - field6["value"] = req.responseBody - - embedData["fields"] = listOf>(field1, field2, field3, field4, field5, field6) + embedData["fields"] = listOf>(field1) val payload: MutableMap = HashMap() payload["embeds"] = arrayOf(embedData) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ef237b1..255a97d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -64,4 +64,7 @@ jwt: logging: discord: - webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==) \ No newline at end of file + webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==) + + level: + root: ERROR diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 138276f..dfdfd02 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -62,4 +62,6 @@ jwt: logging: discord: - webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==) \ No newline at end of file + webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==) + level: + root: INFO \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 91403d0..750afff 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,9 +6,6 @@ server: port: 8080 shutdown: graceful -logging: - level: - root: INFO jasypt: encryptor: