在groovy
grails
项目中,我想外部化log4j.properties
文件,并且我想创建通用相对路径以使其在Linux
和Windows
.
为了外部化,我已经删除了log4j = { ... }
代码并使用以下代码grails-app/conf/Config.groovy
更新了文件。grails-app/conf/spring/resources.groovy
beans = {
log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["./log4j.properties"]
}
}
该log4j.properties
文件位于存在 etc 文件夹的根目录tomcat
中webapps, conf,
。
/tomcat/log4j.properties
上面的代码可以在机器上运行,Windows
但不能在linux
机器上运行。
我尝试了以下方法:
设置以下内容:
arguments = ["${System.properties['catalina.home']}/log4j.properties"]
我也尝试将值设置
grails-app/conf/Config.groovy
为grailsApplication.config.log4j_path = "${System.properties['catalina.home']}/log4j.properties"
并尝试在grails-app/conf/spring/resources.groovy
文件中使用它:
arguments = [grailsApplication.config.log4j_path]
但没有工作。
有人可以告诉我如何设置路径,以便它可以在Windows
和Linux
.
任何帮助表示赞赏。