zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Apache HttpClient库里的日志实现检测原理

Apache日志原理 实现 检测 httpclient
2023-09-14 09:03:09 时间

我有一个业务类,里面指定了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检测就发生了:
clipboard1

查看方法findUserSpecifiedLogClassName:

clipboard2

从system property里取属性org.apache.commons.logging.Log的值:

clipboard3

这里就是我配置的SimpleLog。

要获取更多Jerry的原创文章,请关注公众号"汪子熙":