Skip to content

Commit

Permalink
use model attribute from global model attributes in logger console
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Geißendörfer <[email protected]>
  • Loading branch information
mgeissen committed Mar 6, 2023
1 parent 319afa4 commit 610485d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.otto.babbage.core.loggers

import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.actuate.logging.LoggersEndpoint
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.stereotype.Controller
Expand All @@ -11,17 +10,11 @@ import org.springframework.web.bind.annotation.RequestMapping
@Controller
@RequestMapping(path = ["\${management.endpoints.web.base-path}/logger"])
@ConditionalOnProperty("management.endpoints.loggers.enabled", havingValue = "true", matchIfMissing = false)
class LoggerController(
val loggersEndpoint: LoggersEndpoint,
@Value("\${spring.webflux.base-path:}") val basePath: String,
@Value("\${management.endpoints.web.base-path}") val managementBasePath: String
) {
class LoggerController(val loggersEndpoint: LoggersEndpoint) {

@GetMapping
suspend fun listLoggers(model: Model): String {
model.addAttribute("loggers", loggersEndpoint.loggers())
model.addAttribute("basePath", basePath)
model.addAttribute("managementBasePath", managementBasePath)
return "logger-console"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import org.springframework.web.bind.annotation.ModelAttribute
@ControllerAdvice
class GlobalModelAttributes(
private val webEndpointProperties: WebEndpointProperties,
@Value("\${info.app.name}") private val applicationName: String
@Value("\${info.app.name}") private val applicationName: String,
@Value("\${spring.webflux.base-path:}") val basePath: String,
) {

@ModelAttribute
fun addAttributes(model: Model) {
model.addAttribute("webEndpointBasePath", webEndpointProperties.basePath)
model.addAttribute("managementBasePath", webEndpointProperties.basePath)
model.addAttribute("basePath", basePath)
model.addAttribute("applicationName", applicationName)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class StatusController(
@Autowired(required = false)
private val gitProperties: GitProperties?,
private val statusProperties: StatusProperties,
@Value("\${info.app.name}")private val applicationName: String
@Value("\${info.app.name}") private val applicationName: String
) {

@GetMapping("\${management.endpoints.web.base-path}/status")
Expand Down

0 comments on commit 610485d

Please sign in to comment.