Add logging of requrests
This commit is contained in:
@@ -14,6 +14,8 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-logging")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package org.example
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class HelloController {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(HelloController::class.java)
|
||||
|
||||
@GetMapping("/hello")
|
||||
fun sayHello(): String {
|
||||
fun sayHello(request: HttpServletRequest): String {
|
||||
logger.info("Endpoint /hello was triggered from ${request.remoteAddr}", )
|
||||
return "Hello, World!"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user