I am puzzled. I have been using log4j and Spring successfully for a long time, with log4j setup and configured at the server level by placing log4j.jar and log4j.xml under Tomcat's lib folder. That way the applications don't need their own individual log4j configuration other than instantiating a Logger in the classes.
But when I created a custom filter mypackage.MyFilter that extends org.apache.log4j.spi.Filter, placed it in a jar in the same location as log4j.jar and log4j.xml, and used it for an appender... I get the following error at server startup:
Obviously log4j is getting loaded by Spring's TomcatInstrumentableClassLoader instead of Tomcat's StandardClassLoader. Strange, but no problem so long as things worked. The Spring classloader was defined on Tomcat's conf/context.xml as the loaderClass, in order to enable Spring JPA support. It makes no mention to log4j.
log4j:ERROR A "myPackage.MyFilter" object is not assignable to a "org.apache.log4j.spi.Filter" variable.
log4j:ERROR The class "org.apache.log4j.spi.Filter" was loaded by
----------> Parent Classloader:
] whereas object of type
log4j:ERROR "myPackage.MyFilter" was loaded by [org.apache.catalina.loader.StandardClassLoader@119cca4].
The question now is... how do I make MyFilter be loaded by the same ClassLoader so that things behave as they are supposed to?
On a hunch, I tried cheating and putting MyFilter in the org.apache.log4j.spi package... but no luck.