3

I want to disable console logging messages spawned by org.springframework.* stuff. My log4j.xml looks like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC
  "-//APACHE//DTD LOG4J 1.2//EN"
  "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d %-5p  [%c{1}] %m %n" />
        </layout>
    </appender>

    <logger name="org.springframework">
        <level value="off" />
    </logger>

    <logger name="com.myapp">
        <level value="all" />
        <appender-ref ref="consoleAppender"/>
    </logger>

</log4j:configuration>

But it doesn't work. I still see a lot of DEBUG, INFO messages produces by org.springframework on my console.

What should I change to make it works?

tmporaries
  • 1,523
  • 8
  • 25
  • 39
  • 4
    If you are using Spring 4 it uses Logback rather than Log4J. See my answer here: http://stackoverflow.com/a/23595045/1356423 – Alan Hay Feb 19 '15 at 16:33
  • Correct, everything works after I put logback.xml to /src/main/resources/ – tmporaries Feb 19 '15 at 17:37
  • Possible duplicate of [Spring 4, JPA, Turn off console debug messages](http://stackoverflow.com/questions/23572274/spring-4-jpa-turn-off-console-debug-messages) – OhadR Dec 10 '16 at 22:14

4 Answers4

1

Spring will use the debug level- to get rid of it change the level of Spring to be Info:

<logger name="org.springframework">
    <level value="Info" />
    <appender-ref ref="consoleAppender"/>
</logger>

Edit: Should you not want any Info logs either change the value to be

<level value="Warn" />

Also I see you have specified level value="off" - change this to be Trace, having it off will mean you wont see exceptions

ashosborne1
  • 2,884
  • 1
  • 13
  • 15
1

Springframework logging will not get removed till commons-logging is present in dependency.

You have to disable commons-logging from the dependency in pom.xml file of the web app.

Even after removing commons-logging from pom.xml please check the dependency hierarchy available in Eclipse or STS IDE. This will help in knowing if somehow its getting added because of some other dependency management which we may not be knowing.

After removing dependency just add log4j.logger.org.springframework=ERROR to your log4j configuration. This will help.

SachinSarawgi
  • 2,632
  • 20
  • 28
0

1 add <appender-ref ref="consoleAppender"/> to org.springframework logger

2 make sure log4j.jar and log4j.xml are on the classpath

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • Tried with and without appender. log4j.xml placed in /src/main/resources/log4j.xml - standard maven directory layout. Still not working. – tmporaries Feb 19 '15 at 17:29
0

Add JCL over SLF4J dependency to redirect logs from commons-logging to SLF4J:

    <jcl.over.slf4j.version>1.7.13</jcl.over.slf4j.version>
    ...
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${jcl.over.slf4j.version}</version>
    </dependency>
Abdelhafid
  • 799
  • 7
  • 13