Tomcat6 doesn't seem to load my LogFormatter class
classloader, java, java.util.logging, logging, tomcat6
Solution
I found the solution.
After reading about Tomcat and Class Loading, i found that there is an order which Tomcat follows. It goes like this;
Bootstrap (/jre/lib/ext) -> System (/catalina-home/bin/) -> Common (/catalina-home/lib) -> Webapps.
tomcat-juli.jar which contains the logging stuff is loaded with the "System"-step, so when you place other logging stuff in common, it ignores it cause its already loaded.
The solution is then to place the .jar before tomcat-juli.jar is loaded aka in /jre/lib/ext.´
Edit: It's not always a great idea to keep it in the jre folder, so I found that the best solution is to put it in an endorsed directory.
-Djava.endorsed.dirs=${catalina_home}/endorsed
This endorsed directory will run before System class loading.
Problem
I want to customize my log messages in Tomcat6, and have created a class "MyFormatter" which looks like this: ``` public class LogFormatter extends Formatter { @Override public String format(LogRecord record) { StringBuilder sb = new StringBuilder(); sb.append("LOLCAT--") .append(new Date(record.getMillis())) .append(" \t") .append(record.getThreadID()) .append(" \t") .append(record.getSourceMethodName()) .append(" \t") .append(record.getSourceClassName()) .append(" \t") .append(record.getLevel().getLocalizedName()) .append(": ") .append(formatMessage(record)) .append(System.getProperty("line.separator")); return sb.toString(); } } ``` I've packed this into a .jar and placed in ${catalina.home}/lib. In my logging.properties file I've added the following: ``` 1catalina.org.apache.juli.FileHandler.level = FINE 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.FileHandler.prefix = lolcat. 1catalina.org.apache.juli.FileHandler.formatter = my.package.LogFormatter ``` After sevral attempts trying different packaging, different configs, i decided to try the built in "org.apache.juli.OneLineFormatter" - and this works perfectly. So the config should be fine. The question remains, why doesn't Tomcat6 load my class?