8

In groovy grails project, I want to externalized log4j.properties file and I want to make generic relative path to make it work in Linux and Windows.

To externalize, I have removed log4j = { ... } code from grails-app/conf/Config.groovy And updated the file grails-app/conf/spring/resources.groovy with the following code.

beans = {
    log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
        targetClass = "org.springframework.util.Log4jConfigurer"
        targetMethod = "initLogging"
        arguments = ["./log4j.properties"]
    }
}

The log4j.properties file is in root directory of tomcat, where webapps, conf, etc folders exists. /tomcat/log4j.properties

The above code works on Windows but not in linux machine.

I have tried the following:

  1. Setting the following:

     arguments = ["${System.properties['catalina.home']}/log4j.properties"]
    
  2. Also I have tried setting a value grails-app/conf/Config.groovy as

     grailsApplication.config.log4j_path = "${System.properties['catalina.home']}/log4j.properties"
    

And tried using it in grails-app/conf/spring/resources.groovy file as:

 arguments = [grailsApplication.config.log4j_path]

but non worked.

Can someone tell me how can I set path so that it can work in both Windows and Linux.

Any help is appreciated.

User12111111
  • 1,179
  • 1
  • 19
  • 41
  • Is catalina.home set correctly on Linux install?, can you try catalina.base instead, you could also try arguments = ["classpath:log4j.properties"] – Mike W Jan 05 '17 at 10:22
  • cataline.home is set correctly. I have also tried classpath:log4j.properties. But non worked. When I tried classpath:log4j.properties. the file is in the same tomcat root directory. – User12111111 Jan 05 '17 at 11:00
  • Does the `arguments = ["classpath:log4j.properties"]` option work if you move log4j.properties file to WEB-INF/lib ? – Mike W Jan 05 '17 at 11:48
  • I really appreciate your inputs. But I wanted to externalise log4j.properties file from the war file. – User12111111 Jan 05 '17 at 11:59
  • Understand, I think the simplest method to determine if log4jConfigurer is working with Linux is to put it in known classpath location then work toward being more specific with location – Mike W Jan 05 '17 at 12:04
  • I tried `arguments = ["classpath:log4j.properties"]` and placing the `log4j.properties` file in WEB-INF/lib folder. it did not work. – User12111111 Jan 05 '17 at 12:59
  • you can use System.properties['os.name'].contains('Windows') to know if the system is windows – dynamo Jan 06 '17 at 13:40
  • isn't it just a permission issue? – Michal_Szulc Aug 24 '18 at 13:47

0 Answers0