SL4JF in Tomcat not showing up in log files
Asked Answered
V

3

8

I have installed Tomcat, and using SLF4J as our logging framework. I copied slf4j-api-1.6.4.jar and slf4j-jdk14-1.6.4.jar into the Tomcat library i.e $TOMCAT_HOME/lib.

I assumed that if I use SLF4J, it shall delegate to java.util.Logger, which will delegate to underlying Tomcat logging framework. But when I deploy and check my application, I don't see anything getting logged. All my exception/log information is getting lost.

Is my understanding right, or did I miss anything to keep in class-path?

Vickeyvicki answered 3/3, 2012 at 6:7 Comment(4)
Your configuration seems correct to me, please add your JUL configuration file (logging.properties).Interpreter
You can see github.com/grgrzybek/tomcat-slf4j-logback for a project that replaces Tomcat JULI with pure SLF4J+Logback which doesn't conflict with individual WARs logging configurationHewie
foch, I use the default logging.properties which gets shipped with the server installation. Grzegorz Grzybek, thanks for the link. but i want to know why by defalt its not working. this means SL4J is not useful if we are using tomcat?Vickeyvicki
@Surya: Tomcat (since version 6.0) uses a private package-renamed implementation of Apache Commons Logging (see this page). It just doesn't know how to use SLF4J.Hewie
V
2

Instead of copying the slf4j-api-1.6.4.jar and slf4j-jdk14-1.6.4.jar under $TOMCAT/lib, i shipped these jars with the war application. in this case my exceptions are getting logged.

Vickeyvicki answered 6/3, 2012 at 12:0 Comment(2)
Which configuration file the was picked up when you ship these jars with the war application? This is totally different from what you asked initially.Sling
@Surya, many many thanks for the question and answer. Recently, I just started using TomEE 1.5.1 (tomcat 7.0.32+), and I was trying to get my exceptions and logs out to catalina log file while running TomEE as Windows service (via tomcat7 windows service), and I searched and searched this topic for hours, and this answer finally helped me. thank you so much!Irrefragable
S
1

Probably what you need is to add the system property to the your CATALINA_OPTS.

For Windows systems, add to your %CATALINA_HOME\bin\catalina.bat file:

set CATALINA_OPTS=-Djava.util.logging.config.file=\PATH\TO\YOUR\logging.properties

or on Linux/UNIX systems, add to your $CATALINA_HOME/bin/catalina.sh file:

CATALINA_OPTS=-Djava.util.logging.config.file=/PATH/TO/YOUR/logging.properties

Don't forget that in Linux/UNIX systems, you need to quote if you have more than one parameters in the CATALINA_OPTS, e.g.

CATALINA_OPTS="-Xmx256m -Djava.util.logging.config.file=/PATH/TO/YOUR/logging.properties"

This line is to ensure that your logging.properties file is being loaded when Tomcat is started.

Sling answered 4/3, 2012 at 15:9 Comment(1)
I can see log file filled when an exception is thrown from my application. but when i try to log explicitly its failing. also when i checked the catalina.sh, i can see that logging.properties is being set to the correct properties fileVickeyvicki
M
1

You can configure Tomcat to use log4j as described in its docs, put log4j.properties to $CATALINA_HOME/lib directory and use slf4j-api with slf4j-log4j12 bridge. So you've got clean slf4j API and log4j goodness like DailyRollingFileAppender etc.

Mariammarian answered 14/3, 2012 at 18:49 Comment(1)
the question is about "java.util.Logger" - the default logging for tomcat and not about log4j.Rubenrubens

© 2022 - 2024 — McMap. All rights reserved.