Off the record

Aller au contenu | Aller au menu | Aller à la recherche

vendredi 16 février 2007

Tuning the logging level in Tomcat

Little tip in case ou want to have HIGHER level of logging from tomcat (version 5.5 or higher), because he fails to do something but just says failure ;-)
Tomcat, out of the box, does not include any logging library. However, if you want to make some fine-tuning on the logging, he is ready to achieve your configuration.
At startup (my guess...) Tomcat checks if some special configuration has to be applied, via the "bridge" interface commons logging . This library can be described as a logging implementation abstraction layer. If so, he applies it. Commons logging interface hides the actual implementation, that is, you can use either log4j or any alternative behind the scenes.
Anyway, drop the commons logging and log4j jar files in the common/lib directory, write a log4j.properties file in the common/classes directory, and you should be fine.

Log4j.properties example :

log4j.rootLogger=ERROR, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d %t %-5p %c - %m%n

log4j.logger.org.apache=DEBUG



Pour tester tout ça, rapatriez ce petit projet JSF dans eclipse, ant compile et deploy...

Environment variables in Java

also looking for two lines of code to access the Tomcat directory seamlessly?
Works for any environment variable o' course...

public static void main(String args) {
String tomcatHome = System.getenv("TOMCAT_HOME");
System.out.println("Tomcat Home vaut : "+tomcatHome);
}