Skip to content

Commit

Permalink
[Feat] 요청 정보 로깅 (#44)
Browse files Browse the repository at this point in the history
* feat(HeatlCheck) : 상태 및 업데이트 확인을 위한 컨트롤러를 추가한다

* feat(SecurityConfig) : heatlcheck 컨트롤러는 권한 없이 접근을 허용

* refactor(HealthCheckController) : EOL 추가

* fix(WebConfig) : 요청 헤더 와일드카드 적용

* feat(RequestLoggingInterceptor) : 요청을 받는 가장 앞에서 요청정보를 로깅한다
  • Loading branch information
Due-IT authored Dec 1, 2024
1 parent b2cd642 commit d94e008
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wap.wabi.common

import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor


@Component
class RequestLoggingInterceptor : HandlerInterceptor {
private val logger = LoggerFactory.getLogger(RequestLoggingInterceptor::class.java)

override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
logger.info("Request received from" + request.remoteAddr + "to" + request.requestURI)
return true
}
}
8 changes: 7 additions & 1 deletion wabi/src/main/kotlin/com/wap/wabi/common/config/WebConfig.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.wap.wabi.common.config

import com.wap.wabi.common.RequestLoggingInterceptor
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
class WebConfig : WebMvcConfigurer {
class WebConfig(private val requestLoggingInterceptor: RequestLoggingInterceptor) : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**")
.allowedOrigins(
Expand All @@ -18,4 +20,8 @@ class WebConfig : WebMvcConfigurer {
.allowedHeaders("*")
.allowCredentials(true);
}

override fun addInterceptors(registry: InterceptorRegistry) {
registry.addInterceptor(requestLoggingInterceptor).addPathPatterns("/**")
}
}

0 comments on commit d94e008

Please sign in to comment.