views:

198

answers:

2

I'm packaging up a rails app with warbler and I want app specific logging. I've added the log4j and commons-loggin jar to the WEB-INF/lib directory, and I want to add log4j.properties to the WEB-INF/classes directory. The problem is, I also want environment specific logging, so my staging/production use different properties (ie. INFO instead of DEBUG) than my devel. I can't just do a:

config.java_classes = FileList["lib/log4j-#{RAILS_ENV}.properties"]

because Tomcat seems to look for the specific file log4j.properties. Is there any way to get warbler to rename this file to just log4j.properties? Or is there a better mechanism for app specific, environment specific logging?

A: 

Guess I should just read further down in the warble file itself. You can configure pathmaps for the java_classes. Here's what I used:

config.java_classes = FileList["lib/properties/log4j.properties.#{RAILS_ENV}"]
config.pathmaps.java_classes << "%n"

The only problem I've found is that this doesn't actually put the log4j.properties in the WEB-INF/classes directory anymore. It now puts it in the Root. Seems odd that it specifically says in the docs:

One or more pathmaps defining how the java classes should be copied into WEB-INF/classes

I wouldn't think I'd have to add in that WEB-INF/classes path manually but I did. So finally then, this worked:

config.java_classes = FileList["lib/properties/log4j.properties.#{RAILS_ENV}"]
config.pathmaps.java_classes << "WEB-INF/classes/%n"

using the files log4j.properties.#{RAILS_ENV} in the lib/properties directory

brad
scratch that. It appears that Warbler is not getting the rails_env properly, I'm using warbler (0.9.14). In my cap deploy I set rails_env appropriately, not sure what's going on here, but it always gets log4j.properties.development
brad
+1  A: 

And for the final answer. RAILS_ENV doesn't seem to work in warbler, but looking through the docs on warble config, there's a webxml attribute that contains rails.env, modifying my code to pull the file like:

config.java_classes = FileList["lib/properties/log4j.properties.#{config.webxml.rails.env}"]

Worked like a charm!

brad
Glad that you were able to work out the answer for yourself! Do you get more points for answering your own questions?
Nick Sieger