Turn Off Apache Common Logging

前端 未结 4 606
抹茶落季
抹茶落季 2020-12-02 17:09

I am using Apache Common Logging library in my standalone application. After searching through the web, I try to turn off the logging by using

package javaap         


        
4条回答
  •  情书的邮戳
    2020-12-02 17:53

    As others have pointed out, this is happening because you create the Log object before you set the property.

    One way around this would be to set the property in your Main class' static initialiser block - this will be run when the class is first loaded, and before the static final Log is created:

    public class Main {
    
       static {
          System.setProperty("org.apache.commons.logging.Log",
                             "org.apache.commons.logging.impl.NoOpLog");
       }
    
       // Rest of class as before
    }
    

提交回复
热议问题