RestTemplate 连接池日志

huangapple go评论77阅读模式
英文:

RestTemplate Connection Pooling Logs

问题

有没有办法找出或记录 RestTemplate 连接池的详细信息,我想确保 RestTemplate 正在使用自定义配置的连接池。

英文:

Is there any way to find out or log the details of RestTemplate connnection pool, i want to make sure that RestTemplate is using custom connection pool configured.

答案1

得分: 1

你可以在你的配置文件中为RestTemplate所在的包启用DEBUG级别的日志记录:

    logging:
      level:
        org.springframework.web: DEBUG

并且不要忘记自定义你的log4j2.xml

	<Console name="Console" target="SYSTEM_OUT"
		ignoreExceptions="false">
		<PatternLayout
			pattern="%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
	</Console>

另一种方法是,在你的RestTemplate上添加一个断点,这样你就可以查明它是否正在使用你的自定义连接池。

希望对你有帮助。

英文:

You can activate DEBUG level logging for RestTemplate containing package on your configuration file :

    logging:
      level:
        org.springframework.web: DEBUG

And don't forget to cutomize your log4j2.xml:

&lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;
	ignoreExceptions=&quot;false&quot;&gt;
	&lt;PatternLayout
		pattern=&quot;%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&quot; /&gt;
&lt;/Console&gt;

Another approach, you can add a break point on your RestTemplate and hence you can figure out whether it's taking your custom connection pool or not.

Hope that helps.

答案2

得分: 1

当使用自定义连接池时,就像我使用的apache HttpClientConnection一样,apache提供了PoolingHttpClientConnectionManager类,其中包括一些有用的方法,如getTotalStats(),可以满足我的池统计日志需求。

@Autowired
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager;
poolingHttpClientConnectionManager.getTotalStats();
英文:

When using custom connection pool. Like apache HttpClientConnection which i used, apache provides PoolingHttpClientConnectionManager class which comprise of several useful methods like getTotalStats(), fulfilled my logs for pool stats .

@Autowired
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager;
poolingHttpClientConnectionManager.getTotalStats();

huangapple
  • 本文由 发表于 2020年1月6日 18:07:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610121.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定