[slf4j-user] Trouble setting up logback/slf4j in tomcat.

Sebastien Pennec sebastien at qos.ch
Wed Jan 3 08:55:17 CET 2007


Hello Jacob,

Happy new year!

I have no trouble believing you on this point :) Your configuration actually works
well.

I was wrong when thinking that log4j and logback allow the same use in that 
situation. However, I still think that it does not come from log4j or logback 
internal design. If your configuration works, it is because log4j is the primary 
default implementation that is used by Commons Logging. Log4j is not intercepting the 
internal calls of Tomcat to it's logging implementation: these calls are redirected 
to log4j.

Anyway, thanks for helping clearing the situation :)

Sébastien

Jacob Kjome wrote:
> At 07:14 AM 12/22/2006, you wrote:
>  >Hello Jacob,
>  >
>  >In Marten's situation, I see three important points.
>  >
>  >1. Use logback as a logger for his application.
>  >2. Intercept the logging from other applications and frameworks
>  >running under Tomcat
>  >thanks to jcl104-over-slf4j.
>  >3. Intercept Tomcat's *internal* logging and direct it to logback. I
>  >mean: what the
>  >Tomcat internal classes, like org.apache.catalina.* or
>  >org.apache.tomcat.* classes,
>  >log, by intercepting their calls to commons-logging.
>  >
>  >My email was about that last situation. Placing 
> a jar in commons/lib makes it
>  >available to the applications, but doesn't make it available to the
>  >Tomcat classes
>  >when you launch the server. Maybe I did not express myself very
>  >clearly about this
>  >point, if that is the case, please excuse me.
>  >
>  >As far as I know, log4j and logback are not different at this level.
>  >On the logback
>  >side, we do not have a perfect solution to this problem yet.
>  >
> 
> Actually, I was talking specifically about 
> #3.  I'll say it again.  I put log4j.jar and 
> commons-logging.jar in common/lib.  I put my 
> config file in common/classes.  For 
> Log4j-1.2.xx.jar, the config file has to be 
> log4j.properties because the DTD for log4j.jar 
> doesn't allow for the logger names that Tomcat 
> uses because the DTD defines the <logger> "name" 
> attribute as of type ID and Tomcat's naming 
> scheme includes characters that are not allowed 
> on attributes of type ID.  Log4j-1.3.jar doesn't 
> not have this issue because there is no DTD (it 
> uses Joran, just like Logback).  Here's a sample config for Log4j-1.2.xx...
> 
> log4j.appender.A1=org.apache.log4j.ConsoleAppender
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern=%-5p[%-8.8t]: %39.39c %-6r - %m%n
> 
> log4j.appender.LOCALHOST=org.apache.log4j.RollingFileAppender
> log4j.appender.LOCALHOST.File=${catalina.base}/logs/localhost.log
> log4j.appender.LOCALHOST.MaxFileSize=1000KB
> log4j.appender.LOCALHOST.MaxBackupIndex=1
> log4j.appender.LOCALHOST.layout=org.apache.log4j.PatternLayout
> log4j.appender.LOCALHOST.layout.ConversionPattern=%-5p[%-8.8t]: 
> %39.39c %-6r - %m%n
> 
> log4j.appender.MYAPP=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.MYAPP.File=${catalina.base}/logs/localhost_myapp.log
> log4j.appender.MYAPP.DatePattern='.'yyyy-MM-dd
> log4j.appender.MYAPP.layout=org.apache.log4j.PatternLayout
> log4j.appender.MYAPP.layout.ConversionPattern=%c{1} %-6r - %m%n
> 
> log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myapp]=INFO, 
> MYAPP
> log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/istatus]=false
> 
> log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO, 
> LOCALHOST
> log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=false
> 
> log4j.rootLogger=INFO, A1
> 
> 
> Here's some sample logging from the LOCALHOST log....
> 
> INFO [Thread-1]: 
> Base.[Catalina].[localhost].[/balancer] 18757  - 
> org.apache.webapp.balancer.BalancerFilter: 
> init(): ruleChain: 
> [org.apache.webapp.balancer.RuleChain: 
> [org.apache.webapp.balancer.rules.URLStringMatchRule: 
> Target string: News / Redirect URL: 
> http://www.cnn.com], 
> [org.apache.webapp.balancer.rules.RequestParameterRule: 
> Target param name: paramName / Target param 
> value: paramValue / Redirect URL: 
> http://www.yahoo.com], 
> [org.apache.webapp.balancer.rules.AcceptEverythingRule: 
> Redirect URL: http://jakarta.apache.org]]
> INFO [Thread-1]: 
> .[Catalina].[localhost].[/jsp-examples] 18997  - 
> ContextListener: contextInitialized()
> INFO [Thread-1]: 
> .[Catalina].[localhost].[/jsp-examples] 18997  - 
> SessionListener: contextInitialized()
> INFO [Thread-1]: 
> alina].[localhost].[/servlets-examples] 21591  - 
> ContextListener: contextInitialized()
> INFO [Thread-1]: 
> alina].[localhost].[/servlets-examples] 21591  - 
> SessionListener: contextInitialized()
> INFO [Thread-1]: 
> .[Catalina].[localhost].[/jsp-examples] 818967 - 
> SessionListener: contextDestroyed()
> INFO [Thread-1]: 
> .[Catalina].[localhost].[/jsp-examples] 818967 - 
> ContextListener: contextDestroyed()
> INFO [Thread-1]: 
> alina].[localhost].[/servlets-examples] 820069 - 
> SessionListener: contextDestroyed()
> INFO [Thread-1]: 
> alina].[localhost].[/servlets-examples] 820069 - 
> ContextListener: contextDestroyed()
> 
> 
> Still don't believe me?
> 
> Jake
> 
>  >Cheers,
>  >
>  >Sébastien
>  >
>  >
>  >Jacob Kjome wrote:
>  >> Hi Sebastien,
>  >>
>  >> Why do you say that logback needs to be in
>  >> ${catalina.home}/bin and added to the classpath
>  >> in order to get used for logging by
>  >> Tomcat?  That's not the case for Log4j
>  >> integration.  Simply put log4j.jar and
>  >> commons-logging.jar in common/lib and a config
>  >> file in common/classes and you've now got Tomcat
>  >> logging going through Log4j.  Why would this be different for Logback?
>  >>
>  >> Jake
>  >>
>  >> At 06:38 AM 12/20/2006, you wrote:
>  >>  >Hello Marten,
>  >>  >
>  >>  >I've just answered to your first email on the logback-user list.
>  >>  >
>  >>  >I'll link the answer here not to leave this message unanswered.
>  >>  >
>  >>  >http://qos.ch/pipermail/logback-user/2006-December/000061.html
>  >>  >
>  >>  >Thanks for your interest in slf4j and logback :)
>  >>  >
>  >>  >Sébastien
>  >>  >
>  >>  >
>  >>  >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)
>  >>  >> commons/lib/commons-logging-1.1.jar
>  >>  >> commons/lib/jcl104-over-slf4j-1.1.0-RC1.jar
>  >>  >> commons/classes/logback.xml
>  >>  >>
>  >>  >> In our webapplication (which is a packaged war and doesn't get
>  >>  >unpacked!) I have
>  >>  >> WEB-INF/lib/slf4j-api-1.1.0-RC1.jar
>  >>  >> WEB-INF/lib/logback-classic-0.7.jar
>  >>  >> WEB-INF/lib/logback-core-0.7.jar
>  >>  >> WEB-INF/classes/logback.xml
>  >>  >>
>  >>  >> 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,
>  >>  >>  Marten
>  >>  >>
>  >>  >> _______________________________________________
>  >>  >> user mailing list
>  >>  >> user at slf4j.org
>  >>  >> http://www.slf4j.org/mailman/listinfo/user
>  >>  >>
>  >>  >
>  >>  >--
>  >>  >Sébastien Pennec
>  >>  >sebastien at qos.ch
>  >>  >
>  >>  >Logback: The reliable, generic, fast and flexible logging
>  >framework for Java.
>  >>  >http://logback.qos.ch/
>  >>  >_______________________________________________
>  >>  >user mailing list
>  >>  >user at slf4j.org
>  >>  >http://www.slf4j.org/mailman/listinfo/user
>  >>
>  >> _______________________________________________
>  >> user mailing list
>  >> user at slf4j.org
>  >> http://www.slf4j.org/mailman/listinfo/user
>  >>
>  >
>  >--
>  >Sébastien Pennec
>  >sebastien at qos.ch
>  >
>  >Logback: The reliable, generic, fast and flexible logging framework for Java.
>  >http://logback.qos.ch/
>  >_______________________________________________
>  >user mailing list
>  >user at slf4j.org
>  >http://www.slf4j.org/mailman/listinfo/user
> 
> _______________________________________________
> user mailing list
> user at slf4j.org
> http://www.slf4j.org/mailman/listinfo/user
> 

-- 
Sébastien Pennec
sebastien at qos.ch

Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch/



More information about the slf4j-user mailing list