Results 1 to 8 of 8

Thread: How to turn off Spring logging when in JUnit?

Hybrid View

  1. #1

    Default How to turn off Spring logging when in JUnit?

    While running my suite of JUnit tests, I get tons of INFO logging statements that appear to be coming from Spring. They indicate things like when it creates a new bean and whatnot. Of course, that's all nice if I'm debugging, but when running JUnit tests I'd rather not see all that garbage. I do have a log4j.properties file in my classpath and I believe it is well ahead of any JAR files, so I shouldn't be getting anything from elsewhere that I know of. Can anyone tell me how I can go about telling Spring to hush while I'm running my tests?

    Thanks,
    David

  2. #2
    Join Date
    Aug 2004
    Location
    Tampa, FL
    Posts
    39

    Default

    What does your log4j.properties look like? For me, I can either set my rootLogger to FATAL (to quiet almost everything but FATAL messages) or add this line to get only Spring to be quiet (except for FATAL messages):

    Code:
    log4j.logger.org.springframework=FATAL
    Nilesh Kapadia
    http://www.nileshk.com

  3. #3

    Default

    It's pretty vanilla really. Even after setting "FATAL" for the Spring framework hierarchy I'm getting tons of INFO information back.


    log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder
    log4j.appender.stdout.Target=System.out
    log4j.appender.stdout.layout=org.apache.log4j.Patt ernLayout
    log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n

    #log4j.rootLogger=WARN, stdout
    log4j.logger.com.enttek=DEBUG, stdout
    #log4j.logger.net.sf.hibernate=DEBUG, stdout
    log4j.logger.org.springframework=FATAL, stdout
    #log4j.logger.net.sf.ehcache=DEBUG, stdout

  4. #4
    Join Date
    Nov 2004
    Location
    St. Louis, Missouri USA
    Posts
    33

    Default

    log4j.category.org.springframework=FATAL
    log4j.category.net.sf.hibernate=FATAL

  5. #5

    Default

    No, that didn't help, either, but thanks. I've poured through our code looking for places where it might get set outside of normal configuration. It's just a mystery to me.

  6. #6
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    Everytime I have had this problem, it has always been a classpath issue, i.e., the log4j.properties file loaded is not the one I thought was going to get loaded. Did you try to change something else like the conversion pattern and see if the change gets picked up?
    --Jing Xue

  7. #7

    Default

    Yes, it was a classpath issue. I had that feeling all along, but couldn't find where the extraneous log4j.properties file was. I still don't know where it is, but I know it's in some jar file somewhere that was previously in the classpath. I stripped the classpath down and started adding back jar files until it worked again and finally managed to get rid of all the messages.

    Thanks to everyone who gave me input.
    Dave

  8. #8
    Join Date
    Apr 2008
    Posts
    13

    Default

    I know this is an old thread, but I just solved a similar issue for myself with an interesting revelation which I want to share with others. My dao tests extend very handy AbstractTransactionalDataSourceSpringContextTests class which is from org.springframework.test, however the following logger settings continued to produce lots of messages:

    log4j.logger.com.myapp=DEBUG
    log4j.logger.org.springframework.test=WARN
    The reason is that tests themselves are in com.myapp subpackage and that's why they share its log level (DEBUG)! So it occurs that spring classes produce lots of logs because concrete child instance is enabled for debug logging.

    Hope this would help someone to resolve a mistery!

    P.S. First thing I tried after reading this thread is to search my classpath for log4j* files (including jars) and didn't find anything suspicious.

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 14
    Last Post: Apr 25th, 2008, 05:01 AM
  3. changing spring logging level
    By mavisakal in forum Container
    Replies: 6
    Last Post: Apr 18th, 2006, 09:01 PM
  4. Replies: 29
    Last Post: Apr 12th, 2005, 05:24 PM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •