Trying to enter the properties defined in application.properties/application.yml into a logback.groovy script in a Spring Boot project.
I cannot embed Environment or ApplicationContext in groovy scripts.
Are there any workarounds?
I am not looking for solutions like System.getProperty('spring.profiles.active')
Src / core / resources / logback.groovy
import org.springframework.core.env.Environment @Inject private Environment env; //this is not working. how to get env here? println "spring.profiles.active : ${env.getProperty('spring.profiles.active')}" appender("STDOUT", ConsoleAppender) { encoder(PatternLayoutEncoder) { pattern = "%green(%d{HH:mm:ss.SSS}) [%thread] %highlight(%-5level) %cyan(%logger{36}) - %msg%n" } } if(System.getProperty("spring.profiles.active")?.equalsIgnoreCase("prod")) { root INFO, ["STDOUT", "FILE"] } else { root INFO, ["STDOUT"] }
Src / core / resources / application.yml
spring spring-boot environment-variables groovy logback
xmlking
source share