I have spent quite a bit of time on this and also Google around. So I figured I will share:
This assume you are using rails 3.0 or above, Warbler, and Tomcat 7.0 above
- Download latest log4j.jar and put it in your rails project’s lib directory
- Put your log4j.properties file in the rails root directory
- Add this line in warble.rb: config.java_classes = FileList["log4j.properties"]
- Add this line in warble.rb: config.webxml.jruby.rack.logging = ‘log4j’
Explaination:
Step 2 and 3 will allow warbler to put log4j.properties into the WEB-INF/classes directory
Step 4 will make sure jruby-rack using log4j for logging.
If you run into any issue, check your log4j.properties.
Here is the standard one I use:
log4j.rootLogger=INFO, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.base}/logs/production.log
log4j.appender.R.MaxFileSize=10000KB
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n