Disabling Spring log, to have readable logs

前端 未结 5 1230
醉梦人生
醉梦人生 2020-12-05 07:45

How can I disable Spring logs to have log outputs that I can easily read or someone else can read. An answer to a similar question at, how to disable spring bean loading log

5条回答
  •  误落风尘
    2020-12-05 08:28

    Before you do, you should have get some knowledge of :

    1.How to add maven dependency 
    2.Where to put log4j configuration file
    

    OK, return to the question.The top answer is not working for spring 4.x, if you are using spring4.x try following 3 steps:

    1. remove common-logging from spring-core

      
          org.springframework
          spring-core
          4.3.4.RELEASE
          
              
                  commons-logging
                  commons-logging
              
          
      
      

      Without this step, no matter what you put in log4j configuration file is not working, cause spring is using common-logging my boy!
      PS:Within lots of spring modules, spring-core is the the only module that explicitly depends on commons-logging.

    2. Add SLF4J and log4j

      
          org.slf4j
          jcl-over-slf4j
          1.5.8
      
      
          org.slf4j
          slf4j-api
          1.5.8
      
      
          org.slf4j
          slf4j-log4j12
          1.5.8
      
      
          log4j
          log4j
          1.2.14
      
      
    3. configure log4j.properties(You can also use xml file)

      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=INFO

    Now, the annoying spring debug log is going away.Enjoy coding!

    The answer is from spring.io doc,for origin click here

提交回复
热议问题