Announcement Announcement Module
No announcement yet.
Tomcat 7: Setting logging level for org.springframework libraries Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tomcat 7: Setting logging level for org.springframework libraries

    On Tomcat 7, I am trying to get logging output from the Spring libraries I am using.

    In Tomcat's I have:

    .handlers =, java.util.logging.ConsoleHandler
    java.util.logging.ConsoleHandler.level = ALL = ALL
    #this does not change the logging level...
    org.springframework.level = ALL
    The above code does not cause logging messages from Spring to be logged.

    However, if I also add:

    # this does change the logging level...
    javax.faces.level = ALL
    com.sun.faces.level = ALL
    then I do get logging messages from JSF to be logged.

    Why does the logging not work with Spring and what should I do to make it work?


    I have noticed that when I remove log4j.jar from the classpath, I do get logging from Spring. But when I add log4j.jar to the classpath, the logging from Spring is gone. Can you explain why?

    BTW I do need log4j in my classpath, since one of the other jars I am using, refers to log4j explicitly in its code.
    Last edited by rapt; Apr 8th, 2012, 04:35 PM.

  • #2
    Include a custom log4j.xml or file with your application

    It will be better if you include a custom log4j.xml or file with your application rather than changing the Tomcat log configuration file. You can set the appropriate log levels in your config file and redirect the logs to a custom log file (or other log targets).


    • #3

      See for better alternative to using log4j and commons-logging in Tomcat (downloads:

      Tomcat uses repackaged version of commons-logging which (when you've not added tomcat-juli-adapters.jar explicitely to TOMCAT/lib) uses "standard" java.util.Logging (may it rest in peace forever). To get log4j functionality you can add it to TOMCAT/lib (then you get global configuration) or to every WEB-INF/lib (then every WAR must contain their own log4j.xml).

      I encourage you to look at slf4j (as logging facade) and logback (as logging implementation). API is clean and implementation is not dealing with classloaders (like commons-logging and log4j).

      Grzegorz Grzybek


      • #4
        Hello again

        My first answer was not exactly about your problem, but if you use slf4j and logback, you can include in your WEB-INF/lib:
        • slf4j-api-1.6.4.jar
        • logback-core-1.0.1.jar
        • logback-classic-1.0.1.jar
        • jcl-over-slf4j-1.6.4.jar
        • log4j-over-slf4j-1.6.4.jar

        and proper logback.xml in your WEB-INF classes, for example:
        <?xml version="1.0" encoding="UTF-8"?>
        	<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level (%F:%L\) [%logger{20}] : %msg%n</pattern>
        	<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{user}:%X{ctx}] %-5level {%thread} [%logger{30}] : %msg%n</pattern>
        	<logger name="org.springframework" level="INFO" />
        	<logger name="com.example" level="TRACE" />
        	<root level="INFO">
        		<appender-ref ref="CONSOLE" />
        		<appender-ref ref="FILE" />
        and you'll get nice logging configuration.

        Grzegorz Grzybek