在Grails中使用外部log4j.properties文件的最佳方法是什么?我想使用传统的log4j.properties格式,而不是log4j.groovy样式配置。
我也很好奇,外部配置是否可以与grails war
创建并放入war文件的log4j.properties文件很好地配合使用。如果我从Config.groovy中删除log4j配置,log4j.properties是否仍会放入war文件中?
最佳答案
在Grails 1和2中,有一个logging DSL在开箱即用的Web应用程序中配置和使用,因此您需要从log4j = { ... }
中删除grails-app/conf/Config.groovy
代码
如果要像在典型的Java Web应用程序中一样使用外部配置文件进行日志记录,请使用以下命令更新文件grails-app/conf/spring/resources.groovy
。
beans = {
log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["classpath:log4j.properties"]
}
}
请注意,Log4j附加程序配置中使用的软件包名称可能与您期望的不一样,因为它将添加特定于Grails的前缀...
WARN grails.app.controllers.org.example.BookController - This is a warn log message from BookController
ERROR grails.app.controllers.org.example.BookController - This is an error log message from BookController
关于grails - 在Grails中使用外部log4j.properties文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/518254/