Skip to content

Commit

Permalink
chore(POLABO-108): discord 로그 출력 포멧 수정 및 로그 레벨 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dldmsql committed Aug 22, 2024
1 parent 527e2a1 commit a192981
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*


Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,36 +23,16 @@ class DiscordApiClient(
)
.build()

fun sendErrorLog(req: HttpLog) {
fun sendErrorLog(req: String) {
val embedData: MutableMap<String, Any> = HashMap()

embedData["title"] = "서버 에러 발생"

val field1: MutableMap<String, String> = HashMap()
field1["name"] = "요청 정보"
field1["value"] = req.requestMethod + " " + req.requestURI + " " + req.elapsedTime + "ms"
field1["name"] = "요청"
field1["value"] = req

val field2: MutableMap<String, String> = HashMap()
field2["name"] = "응답 코드"
field2["value"] = req.responseStatus.toString()

val field3: MutableMap<String, String> = HashMap()
field3["name"] = "요청 헤더"
field3["value"] = req.headers.map { it.key + " : " + it.value }.joinToString("\n")

val field4: MutableMap<String, String> = HashMap()
field4["name"] = "요청 본문"
field4["value"] = req.requestBody

val field5: MutableMap<String, String> = HashMap()
field5["name"] = "요청 파람"
field5["value"] = req.parameters.map { it.key + " : " + it.value }.joinToString("\n")

val field6: MutableMap<String, String> = HashMap()
field6["name"] = "응답 본문"
field6["value"] = req.responseBody

embedData["fields"] = listOf<Map<String, String>>(field1, field2, field3, field4, field5, field6)
embedData["fields"] = listOf<Map<String, String>>(field1)

val payload: MutableMap<String, Any> = HashMap()
payload["embeds"] = arrayOf<Any>(embedData)
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ jwt:

logging:
discord:
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)

level:
root: ERROR
4 changes: 3 additions & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ jwt:

logging:
discord:
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)
level:
root: INFO
3 changes: 0 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ server:
port: 8080
shutdown: graceful

logging:
level:
root: INFO

jasypt:
encryptor:
Expand Down

0 comments on commit a192981

Please sign in to comment.