Add logging of requrests

This commit is contained in:
2024-09-06 09:30:42 +02:00
parent d768b37850
commit 2d8cc727c4
2 changed files with 8 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ repositories {
dependencies { dependencies {
implementation("org.springframework.boot:spring-boot-starter-web") 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("org.springframework.boot:spring-boot-starter-test")
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
} }

View File

@@ -1,13 +1,18 @@
package org.example 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.GetMapping
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
@RestController @RestController
class HelloController { class HelloController {
private val logger = LoggerFactory.getLogger(HelloController::class.java)
@GetMapping("/hello") @GetMapping("/hello")
fun sayHello(): String { fun sayHello(request: HttpServletRequest): String {
logger.info("Endpoint /hello was triggered from ${request.remoteAddr}", )
return "Hello, World!" return "Hello, World!"
} }
} }