我正在尝试配置Grails,以便使用将生产和开发模式分开的外部Log4j2配置文件。它应该侦听配置更改,并在一段时间后刷新。
对于Grails 2.x,可以通过注册Log4jConfigurer
bean来完成,如下所示:
switch (Environment.current) {
case Environment.PRODUCTION:
log4jConfigurer(MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["classpath:ogc-log4j.xml", 30000]
}
case Environment.DEVELOPMENT:
log4jConfigurer(MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["classpath:log4j-dev.xml", 30000]
}
}
由于某些原因,这种方法在Grails 3.x中不起作用。如何在Grails 3.3.3或Spring Boot中做到这一点(我猜它应该可以工作,因为Grails 3.x基于Spring Boot)?
最佳答案
从3.3.3的grails
而不是将其包含在Java代码中。
环境配置已移至YML配置文件。
我们可以将不同的值传递到不同的环境并更改log4j的配置
请参阅文档
documentaion for Enviroment configuration
关于spring - 登录Grails:使用Log4j2重新加载外部配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55571280/