commons-logging のパスの覚え書き

tomcat で webapp の実行環境内で

 URL url = Thread.currentThread().getContextClassLoader().getResource("");

等とすると、きっちりパスとしては apps/WEB-INF/classes 以下をみるのに、何故か commons-logging + log4j で、FileAppender で相対パス指定すると、Tomcat の実行ディレクトリ配下からの相対パスになってしまい、不思議に思っていたが下記のような事がある模様。

Commons_Logging_FUD - Commons Wikiより抜粋。

First, move the jar out of the System classloader:

mv $CATALINA_HOME/bin/commons-logging-api.jar $CATALINA_HOME/server/lib

Secondly, in the $CATALINA_HOME/bin directory, there are two scripts which reference commons-logging-api.jar directly: catalina.sh and catalina.50.sh (or the respective .bat files for Windows). Replace the "$CATALINA_HOME"/bin/commons-logging-api.jar references with "$CATALINA_HOME"/server/lib/commons-logging-api.jar.

commons-logging is now removed from the System class loader but still available through the Catalina class loader. However, as you had to add it to the CLASSPATH in the catalina startup files, it is also available through the root class loader (because it is in the CLASSPATH). This is unfortunate, but no problem because you can override this with dropping your desired commons-logging jar into WEB-INF/lib.

Finally, let me quote another commons-logging advocacy page which sometimes is used as an indicator that even its author considers commons-logging a bad idea. In the words of Rod Waldhoff, one of the inventors of commons-logging (on [WWW] his weblog):

The purpose of Commons Logging is not to isolate your code from changes in the underlying logging framework. (That's certainly easy enough to do on your own, and not really worth doing in the first place given the ease of switching from one logging framework to another.) The purpose of Commons Logging is not to somehow be more useful than actual logging frameworks by being more general. The purpose of Commons Logging is not to somehow take the logging world by storm. In fact, there are very limited circumstances in which Commons Logging is useful. If you're building a stand-alone application, don't use commons-logging. If you're building an application server, don't use commons-logging. If you're building a moderately large framework, don't use commons-logging. If however, like the Jakarta Commons project, you're building a tiny little component that you intend for other developers to embed in their applications and frameworks, and you believe that logging information might be useful to those clients, and you can't be sure what logging framework they're going to want to use, then commons-logging might be useful to you.

とりあえず、余力があるときに試してみるためにメモ。ただ最後の方の commons-logging の目的とは、のくだりについては個人的に考えていたことと違っていて、驚く。あれ、struts で commons-logging 使ってるよね、と。。。