I use log4j and he work just fine. A log4j.xml file is in my classpath, i use appender and category... again, it's work just fine for my code or code of other librairy.

But the spring classes continue to flood stdout with message i want to log elsewhere. It's beggin to be anoying.

Offending message : org.springframework.jms : some error.... More generally, all classes of the org.springframework package send message to stdout.

So i put this in my log4j.xml :

<appender name="JMS-ERROR" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="tms.logs.folder/tms.logs.files.prefix-jms-error.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="2"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="**DVIDEA** %d{dd.MM.yyyy HH:mm:ss} %c  %m%n"/>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
        <param name="LevelMin" value="DEBUG" />
        <param name="LevelMax" value="FATAL" />

<category name="org.springframework.jms" additivity="false">
    <appender-ref ref="JMS-ERROR"/>

It's work with other librairie. Why not spring ?

I do some research, and it's appeart that Spring use common-logging, and not log4j. It's that a possible cause ? Any workaround ?

I have try to add a log4jConfigurationListener to my web.xml. he's working but i stil dont have any control over the spring error message.


Edit :

Some more info :

  • i use Tomcat 5.5
  • a ( old log4j config ) is still present for historical reason. I'v try to remove it => no change.

EDIT 2 : I use the following workaround, but i'm not happy with it : it's not configurable

java.util.logging.Logger springLogger = Logger.getLogger("org.springframework.jms");

No correct solution


Note that in the Spring samples they are using slf4j to route log messages from Commons Logging to log4j. In Maven's pom.xml it looks this way:

<!-- Exclude Commons Logging -->
        <!-- Exclude Commons Logging in favor of SLF4j -->

<!-- Add slf4j API -->

<!-- Add Commons Logging -> slf4j bridge -->

<!-- Add slf4j -> log4j bridge -->

You might need:

<bean id="log4jInitialization"
        <property name="targetClass"
            value="org.springframework.util.Log4jConfigurer" />
        <property name="targetMethod" value="initLogging" />
        <property name="arguments">

Spring uses Apache Commons Logging, which in turn decides whether to use STDOUT (via java.util.logging) or Log4j. If you're getting Spring output on STDOUT, then commons-logging hasn't located log4j for some reason.

If you set the system property org.apache.commons.logging.diagnostics.dest, commons-logging can be configured to log its diagnostics, telling you what steps it is taking to determine in log4j is present.

So in your tomcat startup script, set the system property, e.g.


You must use SLF4J, and include the bridge to the logging platform you want (log4j) but you must also exclude commons-logging from all the other places it might be pulled in. It helps to have an IDE to do this, or you can put a dummy entry in for commons-logging. For details on that, see the SLF4J FAQ entry

A previous answer mentioned using the com.springsource artifacts, however if you are using Maven Central the right way to do it is:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow