diff --git a/wabi/src/main/kotlin/com/wap/wabi/common/RequestLoggingInterceptor.kt b/wabi/src/main/kotlin/com/wap/wabi/common/RequestLoggingInterceptor.kt new file mode 100644 index 0000000..ebef885 --- /dev/null +++ b/wabi/src/main/kotlin/com/wap/wabi/common/RequestLoggingInterceptor.kt @@ -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 + } +} diff --git a/wabi/src/main/kotlin/com/wap/wabi/common/config/WebConfig.kt b/wabi/src/main/kotlin/com/wap/wabi/common/config/WebConfig.kt index 282de3c..a1a5313 100644 --- a/wabi/src/main/kotlin/com/wap/wabi/common/config/WebConfig.kt +++ b/wabi/src/main/kotlin/com/wap/wabi/common/config/WebConfig.kt @@ -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( @@ -18,4 +20,8 @@ class WebConfig : WebMvcConfigurer { .allowedHeaders("*") .allowCredentials(true); } + + override fun addInterceptors(registry: InterceptorRegistry) { + registry.addInterceptor(requestLoggingInterceptor).addPathPatterns("/**") + } } \ No newline at end of file