Skip to content

Commit 51c9845

Browse files
authored
Merge pull request #28 from DDD-Community/feature/POLABO-108
chore(POLABO-108): discord 로그 출력 포멧 수정 및 로그 레벨 수정
2 parents aad02d5 + a192981 commit 51c9845

File tree

5 files changed

+21
-51
lines changed

5 files changed

+21
-51
lines changed

src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt

+9-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.ddd.sonnypolabobe.global.security
22

33
import com.ddd.sonnypolabobe.global.exception.CustomErrorCode
44
import com.ddd.sonnypolabobe.global.util.DiscordApiClient
5-
import com.ddd.sonnypolabobe.global.util.HttpLog
65
import com.ddd.sonnypolabobe.logger
76
import com.fasterxml.jackson.databind.ObjectMapper
87
import io.jsonwebtoken.JwtException
@@ -16,7 +15,6 @@ import org.springframework.web.util.ContentCachingRequestWrapper
1615
import org.springframework.web.util.ContentCachingResponseWrapper
1716
import org.springframework.web.util.WebUtils
1817
import java.io.UnsupportedEncodingException
19-
import java.time.LocalDateTime
2018
import java.util.*
2119

2220

@@ -42,30 +40,19 @@ class JwtExceptionFilter(
4240
val startedAt = System.currentTimeMillis()
4341
filterChain.doFilter(requestWrapper, responseWrapper)
4442
val endedAt = System.currentTimeMillis()
45-
logger().info(
46-
"\n" +
47-
"[REQUEST] ${request.method} - ${request.requestURI} ${responseWrapper.status} - ${(endedAt - startedAt) / 10000.0} \n" +
48-
"Headers : ${getHeaders(request)} \n" +
49-
"Parameters : ${getRequestParams(request)} \n" +
50-
"Request body : ${getRequestBody(requestWrapper)} \n" +
51-
"Response body : ${getResponseBody(responseWrapper)}"
52-
)
43+
44+
val message = "\n" +
45+
"[REQUEST] ${request.method} - ${request.requestURI} ${responseWrapper.status} - ${(endedAt - startedAt) / 10000.0} \n" +
46+
"Headers : ${getHeaders(request)} \n" +
47+
"Parameters : ${getRequestParams(request)} \n" +
48+
"Request body : ${getRequestBody(requestWrapper)} \n" +
49+
"Response body : ${getResponseBody(responseWrapper)}"
50+
logger().error(message)
5351
if (responseWrapper.status >= 400 && getResponseBody(responseWrapper).contains(
5452
CustomErrorCode.INTERNAL_SERVER_EXCEPTION.message
5553
)
5654
) {
57-
this.discordApiClient.sendErrorLog(
58-
HttpLog(
59-
request.method,
60-
request.requestURI,
61-
responseWrapper.status,
62-
(endedAt - startedAt) / 10000.0,
63-
getHeaders(request),
64-
getRequestParams(request),
65-
getRequestBody(requestWrapper),
66-
getResponseBody(responseWrapper)
67-
)
68-
)
55+
this.discordApiClient.sendErrorLog(message)
6956
}
7057
}
7158
} catch (e: JwtException) {

src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt

+5-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ddd.sonnypolabobe.global.util
22

3+
import com.sun.jndi.ldap.LdapPoolManager.trace
34
import org.springframework.beans.factory.annotation.Value
45
import org.springframework.http.MediaType
56
import org.springframework.http.client.reactive.ReactorClientHttpConnector
@@ -22,36 +23,16 @@ class DiscordApiClient(
2223
)
2324
.build()
2425

25-
fun sendErrorLog(req: HttpLog) {
26+
fun sendErrorLog(req: String) {
2627
val embedData: MutableMap<String, Any> = HashMap()
2728

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

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

34-
val field2: MutableMap<String, String> = HashMap()
35-
field2["name"] = "응답 코드"
36-
field2["value"] = req.responseStatus.toString()
37-
38-
val field3: MutableMap<String, String> = HashMap()
39-
field3["name"] = "요청 헤더"
40-
field3["value"] = req.headers.map { it.key + " : " + it.value }.joinToString("\n")
41-
42-
val field4: MutableMap<String, String> = HashMap()
43-
field4["name"] = "요청 본문"
44-
field4["value"] = req.requestBody
45-
46-
val field5: MutableMap<String, String> = HashMap()
47-
field5["name"] = "요청 파람"
48-
field5["value"] = req.parameters.map { it.key + " : " + it.value }.joinToString("\n")
49-
50-
val field6: MutableMap<String, String> = HashMap()
51-
field6["name"] = "응답 본문"
52-
field6["value"] = req.responseBody
53-
54-
embedData["fields"] = listOf<Map<String, String>>(field1, field2, field3, field4, field5, field6)
35+
embedData["fields"] = listOf<Map<String, String>>(field1)
5536

5637
val payload: MutableMap<String, Any> = HashMap()
5738
payload["embeds"] = arrayOf<Any>(embedData)

src/main/resources/application-dev.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@ jwt:
6464

6565
logging:
6666
discord:
67-
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)
67+
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)
68+
69+
level:
70+
root: ERROR

src/main/resources/application-local.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,6 @@ jwt:
6262

6363
logging:
6464
discord:
65-
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)
65+
webhook-uri: ENC(yfeX3WHXQdxkVtasNl5WLv6M/YlN+dVFUurjxGIddstjjipt+KryWKvLu1wDmdGjpuEhUHyaABg4gFWRMk9gNlxSQEE/G1twbuvkOvT0pyFWycVVJ6ryU/v9pDBOS1PSKJY7L3NP66gOGnam6nOvf0Y+F45zZvXj8/sdtR6N798U6fGjFDxOLQ==)
66+
level:
67+
root: INFO

src/main/resources/application.yml

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ server:
66
port: 8080
77
shutdown: graceful
88

9-
logging:
10-
level:
11-
root: INFO
129

1310
jasypt:
1411
encryptor:

0 commit comments

Comments
 (0)