版权声明:本文为博主汪子熙原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1438509
我有一个业务类,里面指定了org.apache.commons.logging.impl.SimpleLog作为日志记录的实现。代码如下。
public SimpleContactCreator(){
enableHeaderWireAndContextLogging();
}
private void enableHeaderWireAndContextLogging(){
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
}
在运行时,这个SimpleLog的实现是如何被HttpClient检测出来的?
当我调用HttpClientBuilder.create().build()的时候,log检测就发生了:
查看方法findUserSpecifiedLogClassName:
从system property里取属性org.apache.commons.logging.Log的值:
这里就是我配置的SimpleLog。