Jed Schneider is a Ruby and Rails software developer for the Medical University of South Carolina. He was a pro cyclist at one time, now he just rides for fun.
crashland, again.
I've been working on getting applications deployed via Warbler and Tomcat and one of the annoying features is the loss of logging to application specific log files when being deployed without any extra setup. It also turns out that besides me not getting warbler apps to deploy on Tomcat 5.x, the procedure for setting logging up is markedly different than on Tomcat 7. So, since I was able to get the apps running on 7, I went about figuring out how to get the application specific logging setup there also. So, I am assuming many things, in part:
Why would I go through configuration hell to setup Tomcat, you say? I can think of no reason that satisfies this answer, but if you are like me, the less you have to deal with adding something 'new' to the system the better off you are. This is a perfect way to be able to work in a reasonable development paradigm (aka Ruby and Rails) and still be able to use the existing infrastructure (java web application servers) with management being less concerned about supporting something 'new'. Also, jRuby is quite performant, and the one click upload deployment strategy of Tomcat is sure nice (or scp your war into the webapps dir).
The rest of this guide is a rough outline of how to get Tomcat 7, Warbler, jRuby, and app specific logging with log4j all working together.
For the most part, to setup your tomcat server to use log4j, you can follow the handy guide with the following notes:
output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib" what the guide really means is that there are some extra files you can download from the extras link and that when you download them they are assuming you are putting them in some file structure 'output/extras'. No need to ack the tomcat project for that output directory like I did. The extras you are interested in are (linked at time of writing - so keep in mind software updates)
$ tail -f $CATALINA_HOME/logs/tomcat.log to see as you use the app that there is logging going on.Warbler is a nice little gem that I have been using a lot of lately and been very thankful for Nick Sieger's help getting my apps at work off the ground.
There are several ways that you can setup your warble configuration and ways to use warbler. For me it was effective to create the war with the command line tool `warble war` from the root of my rails app and which will generate your war file in the root of the project. But, before you can war its best to bundle and get jRuby setup.
So, follow this guide to setup your rails 2.3.x app to use Bundler. Warbler will use your Gemfile to pull in the gems to your war and make it a standalone application.
first, I use rvm and i have a gemset setup for each app I use.
I use jRuby for waring up the file and all the other commands in the tutorial.
Setting up your Gemfile for jRuby is a bit different. You may choose to catch the gem dependencies with a similar block:
The activerecord-jdbc-adapter gives you a generator that will setup your rails app to use the jdbc adapters when necessary. $ script/generate jdbc
generates all the appropriate files for you.
At this point I would probably try deploying the app on Tomcat to see if it will run before adding any more complexity with the app specific logging.
Your workflow for this might be something like:
$ warble war
$ cp app.war $CATALINA_HOME/webapps/app.war
$ open http://localhost:8080/app
But you can also use the tomcat manager to upload your file.
The app should load up and you should see output in your tomcat.log file.
So now you have the logging working on a real app running on tomcat. The rest are just details to get the file structure appropriate for Tomcat to get the information in the right places. First, run
$ warble config
which creates a new file in your config directory. open that up and uncomment the following line, adding the appropriate file:
config.java_classes = FileList["log4j.properties"]
now, copy the log4j.properties file from your tomcat root to the root of your rails project and change the name of the log file in the properties.
log4j.appender.R.File=${catalina.home}/logs/app.log
now, copy the jar files you downloaded earlier into your lib directory. Redeploy the app, and then look inside the log directory, you should see an app.log file created on the first request to the app, or if you restart Tomcat, it should generate on startup. Now, if you need log info, you can go straight here to see the standard rails logging you expect. Hurray!