开发者

Warbler config.java_classes and log4j.properties

开发者 https://www.devze.com 2022-12-14 19:16 出处:网络
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/

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开发者_Go百科 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?


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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号