大佬教程收集整理的这篇文章主要介绍了java – 如何在Spring-boot应用程序中为Apache Tomcat中的AccessLogValve设置属性requestAttributesEnabled?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我们有一个独立的spring-boot应用程序,我们希望在其中设置访问日志模式
> X-forWARDed-for标头存在于请求中:它应作为第一个字段包含在日志中
> X-forWARDed-for header在请求中不存在:它应该被远程ip地址替换
当我们使用以下设置运行@R_169_9616@程序时,我们只获取远程IP地址
server.tomcat.accesslog.directory= %r" %s %b
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.suffix=.log
例如:
192.168.25.265 - - - [12/Sep/2016:10:20:56 +0200] "GET /myapp http/1.1" 200 125922
我们还尝试将属性server.tomcat.accesslog.pattern设置为
%h %{X-ForWARDed-For}i %l %u %t "%r" %s %b
然后我们得到远程IP地址和X-forWARDed-for标头值.
例如:
192.168.25.265 192.168.21.65 - - - [12/Sep/2016:10:20:56 +0200] "GET /myapp http/1.1" 200 125922
但是,基于链接https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html,当x-forWARDed-for不存在时,tomcat支持包含远程ip地址的此要求.这可以通过添加属性’requestAttributesEnabled’来实现
我们尝试添加该属性
server.tomcat.accesslog.requestAttributesEnabled
但没有发生任何影响.
它似乎没有实现,因为它不存在于此:http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
我们使用EmbeddedServletContainerCustomizer的实现实现了一个变通方法,如How do I configure the location and name of tomcat access log in spring-boot?所述,
我们在哪里添加:
accessLogValve.setrequestAttributesEnabled(true);
它按预期工作.
但是我们希望能够通过spring-boot将requestAttributesEnabled设置为配置属性,如:
server.tomcat.accesslog.requestAttributesEnabled=true
而不是需要在我们的所有服务中使用此定制器.
以上是大佬教程为你收集整理的java – 如何在Spring-boot应用程序中为Apache Tomcat中的AccessLogValve设置属性requestAttributesEnabled?全部内容,希望文章能够帮你解决java – 如何在Spring-boot应用程序中为Apache Tomcat中的AccessLogValve设置属性requestAttributesEnabled?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。