Announcement Announcement Module
Collapse
No announcement yet.
How to turn off Spring logging when in JUnit? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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

      Comment


      • #4
        log4j.category.org.springframework=FATAL
        log4j.category.net.sf.hibernate=FATAL

        Comment


        • #5
          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.

          Comment


          • #6
            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?

            Comment


            • #7
              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

              Comment


              • #8
                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.

                Comment

                Working...
                X