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?
In Grails 1 and 2, there's a logging DSL that is configured and used in an out-of-the-box webapp, so you'll want to remove the log4j = { ... }
code from grails-app/conf/Config.groovy
If you want to use an external configuration file for logging like in a typical Java web application, then update the file grails-app/conf/spring/resources.groovy
with the following.
beans = {
log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["classpath:log4j.properties"]
}
}
Note that the package name used in your Log4j appender configuration will probably not be what you expect, since it will have a Grails-specific prefix added onto it...
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
If you're using 1.0.x series:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With