tags:

views:

2390

answers:

3

What's the best way to use an external log4j.properties file within Grails? I'd like to use the traditional log4j.properties format rather than a log4j.groovy style configuration.

I'm also curious if the external configuration will play nicely with the log4j.properties file that's created by grails war and put into the war file. If I remove the log4j configuration from Config.groovy will the log4j.properties still be put into the war file?

+2  A: 

Check out the Log4J Plugin which states:

"Some old-school Java developers are more comfortable with log4j.xml even though the configuration file is much larger. This plugin provides a way to disable the default Log4j DSL and allow the use of log4j.xml either in the original form, or in Groovy MarkupBuilder style."

I haven't used it myself so can't speak to its usability in the WAR context.. Just WAR up your app, and then try it out.. It should be under the WEB-INF folder somewhere obvious. If that doesn't work, Mingfai on the grails user list can probably help you out.

j pimmel
+1 This is a reasonable solution, but won't quite work for me, since I'm using Grails 1.0.3 (the plugin only works for 1.1). A helpful answer, though. Thanks.
Rob Hruska
+3  A: 

If you're using 1.0.x series:

  • copy War.groovy from $GRAILS_HOME/scripts to your $APP/scripts
  • comment out lines 145 and 154 of the copied War.groovy
  • put your log4j.properties into $APP/grails-app/conf
  • run $ grails war, and it will prompt you to choose which War script to run, then choose your local one (usually #1).
chanwit
A: 

At least in 1.0.x series (not checked in 1.1) forget about Grails support and rely directly on Spring. Just use the log4jConfigLocation parameter in web.xml. More info here

Juanjo García