[logback-user] Trouble setting up logback in tomcat.
sebastien at qos.ch
Wed Dec 20 13:36:19 CET 2006
Thanks for using logback :)
Your web-app seems to be configured fine. Under Tomcat, or Jetty, it is sufficient
to put the classic, core and slf4j-api jars in WEB-INF/lib and a configuration file
in WEB-INF/classes. I've just tried with a fresh installation of Tomcat 5.5.20, and
it went well. For this test, I didn't touch any configuration or jars in the Tomcat
directory, I only added to the webapps directory the following files:
With this setup, my demo app logs to a given file, and Tomcat logs as usual. I
suggest that you try this setup, without any attempt to intercept Tomcat's internal
logging for now.
If you want Tomcat to use SLF4J instead of commons-logging, it's a bit more
complicated. Placing jars in the $TOMCAT_HOME/commons/lib/ directory will share
logback's jars between web-applications, but will not make it available to the
server. To influence Tomcat's behaviour, you have to put the jars in
$TOMCAT_HOME/bin/ and add them to the server's classpath by editing the file
catalina.sh if you're using startup.sh to launch Tomcat, otherwice edit catalina.bat.
Using logback as the implementation used by both tomcat *and* all web-apps running
under the server is not something that I have tested until now. I'll test that more
deeply and keep you informed.
Marten Deinum wrote:
> For my current project I would like to switch out all the logging which is
> currently being done by log4j and here en there by commons-logging to one
> framework. After some searching I discoverd SLF4J and Logback as the
> successor to log4j. In your code I swapped out all the log4j and
> commons-logging to the SLF4J api and I want to use Logback as my logger. I
> converted our log4j.properties file with the configuration converter on the
> website, so I assume that is correct.
> In the tomcat directory I have the following logging libs (I want tomcat to
> use SLF4J to)
> In our webapplication (which is a packaged war and doesn't get unpacked!) I
> The contents of the logback.xml in the commons directory just contains a
> simple ConsoleAppender and is configured to WARN level.
> The file in the WEB-INF directory is configured as a file which should be
> written to c:\logs\mylog.log, configured different levels for different
> packages we use.
> However logback isn't getting picked up, everything is being logged by the
> java.util classes (as it appears thatone is being initialized by tomcat
> instead of the logback logger).
> I tried different configurations, all the logback/slf4j jars in the
> commons/lib and one config file in commons/classes. Different jars in
> commons/lib and WEB-INF/lib but until now everytime with the same result,
> only logging to JUL and nothing to logback and my configured logfile.
> Currently I'm at a loss on what to do and how to make it work. I need some
> assistance with this.
> Kind Regards,
sebastien at qos.ch
Logback: The reliable, generic, fast and flexible logging framework for Java.
More information about the Logback-user