Hi,
I'm using jetty6 with SLF4J and java logging and have been trying to add a custom log Formatter, but no matter what I try I can't seem to get it to work.
I have a Formatter, like this:
package mycode.logging;
public class DeadSimpleFormatter extends SimpleFormatter
{
// Nothing here at all - just an empty subclass of SimpleFormatter.
}
I want to use this as the default for my jetty logging, so I've created a ${jetty.home}/resources/logging.properties file:
handlers=java.util.logging.FileHandler
.level=INFO
java.util.logging.FileHandler.pattern=logs/test_%u.%g.log
java.util.logging.FileHandler.limit=90000
java.util.logging.FileHandler.count=20
java.util.logging.FileHandler.formatter=mycode.logging.DeadSimpleFormatter
mycode.level=INFO
I create a jar file logging.jar, containing the DeadSimpleFormatter class. I put this jar into ${jetty.home}/lib/ext.
I start jetty:
java -Djava.util.logging.config.file=resources/logging.properties
-jar start.jar etc/jetty-logging.xml etc/jetty.xml
I can see the output file being created. It follows the rules for limit and count as defined in my properties file. But it doesn't use my formatter - it reverts to the default XmlFormatter. I don't see any errors out of stdout or stderr.
If I change the logging.properties file to set the formatter like this:
java.util.logging.FileHandlerformatter=java.util.logging.SimpleFormatter
...then it works - the log file is written out using the normal SimpleFormatter. So I'm confident that my properties are ok and I have my slfj jars etc. all correct. It's just that Jetty doesn't like my DeadSimpleFormatter.
Since there's nothing - literally! - in DeadSimpleFormatter, I figure this may be a class loading issue. I tried explicitly adding the jar file like this:
java -Djetty.class.path=/mypathtojettyhome/lib/ext/logging.jar
-Djava.util.logging.config.file=resources/logging.properties -jar start.jar
etc/jetty-logging.xml etc/jetty.xml
...but no joy.
I put a main method into my DeadSimpleFormatter and checked that I could run the jar:
java -jar lib/ext/logging.jar
...This works, so I'm pretty sure my jar is ok.
Does anyone have any idea what's going on here? I've tried every combination I can think of.
Thanks, Alastair