Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off Spring 3 debug logging?

Tags:

spring

log4j

I would like to turn off log4j logging for Spring 3.1 while leaving things on debug for my own code.

I tried sticking this line into my log4j.properties:

log4j.category.org.springframework = WARN 

To get this:

# Root Logger Setup:  Includes the level of reporting and appenders -> where
#                     log messages get sent                                              
log4j.rootLogger                            = DEBUG,ca,fa

log4j.category.org.springframework = WARN

#ca - Console Appender - Send messages to the console
log4j.appender.ca                          = org.apache.log4j.ConsoleAppender
log4j.appender.ca.layout                   = org.apache.log4j.PatternLayout
log4j.appender.ca.layout.ConversionPattern = [acme]: [%-5p] - %d{yyyy-MMM-dd HH:mm:ss} -  %c{1}:%M(): %m%n



#fa - File Appender - Send messages to a log file
log4j.appender.fa                            = org.apache.log4j.RollingFileAppender
log4j.appender.fa.File                       = acme.log
log4j.appender.fa.MaxFileSize                = 100KB
log4j.appender.fa.MaxBackupIndex             = 10
log4j.appender.fa.Threshold                  = DEBUG
log4j.appender.fa.layout                     = org.apache.log4j.PatternLayout
log4j.appender.fa.layout.ConversionPattern   = [%-5p] - %d{yyyy-MMM-dd HH:mm:ss} -  %c{2}:%M(): %m%n 

No luck in shutting off the debug output from Spring though.

Thanks in advance for any help

Steve

like image 547
Steve Avatar asked Jun 05 '12 21:06

Steve


People also ask

How do I disable debug logs in spring?

In your case you must set logging. level. root on one of level from INFO, WARN, ERROR,FATAL or OFF to turn off all logging.

How do I turn off Info logs in slf4j?

To disable this behavior, you must add a logback configuration file called logback. xml in your java classpath root. You can download this minimal logback. xml file and add it in the src/main/resources directory for a maven project or beside fr directory for a simple java project.


2 Answers

Are all your dependencies in place?

1.3.2.3 Using Log4J

Many people use Log4j as a logging framework for configuration and management purposes. It's efficient and well-established, and in fact it's what we use at runtime when we build and test Spring. Spring also provides some utilities for configuring and initializing Log4j, so it has an optional compile-time dependency on Log4j in some modules.

To make Log4j work with the default JCL dependency (commons-logging) all you need to do is put Log4j on the classpath, and provide it with a configuration file (log4j.properties or log4j.xml in the root of the classpath). So for Maven users this is your dependency declaration:

<dependencies>
   <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>3.0.0.RELEASE</version>
      <scope>runtime</scope>
   </dependency>
   <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
      <scope>runtime</scope>
   </dependency>
</dependencies> 

And here's a sample log4j.properties for logging to the console:

log4j.rootCategory=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n

log4j.category.org.springframework.beans.factory=DEBUG
like image 134
Tankhenk Avatar answered Oct 05 '22 23:10

Tankhenk


I figured this out.

In my classpath I have a directory C:\Classes for convenience when I am experimenting with things. I had another log4.properties file there, which was superseding the one packaged in my WAR making it look like the technique below wasn't working. I renamed the log4.properties in my C:\Classes and all is well.

Thanks to everyone who took a look and thanks to the people at Spring Source who made doing this necessary. It is good to know that an extensive level of debugging is easily available to me when I want it instead of just getting a black box.

like image 35
Steve Avatar answered Oct 06 '22 00:10

Steve