Announcement Announcement Module
No announcement yet.
How to turn off Spring logging when in JUnit? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 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?


  • #2
    What does your 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):



    • #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.layout=org.apache.log4j.Patt ernLayout
      log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n

      #log4j.rootLogger=WARN, stdout, stdout, stdout, stdout, stdout


      • #4


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


          • #6
            Everytime I have had this problem, it has always been a classpath issue, i.e., the 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?


            • #7
              Yes, it was a classpath issue. I had that feeling all along, but couldn't find where the extraneous 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.


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

                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.