From 0072a9391542cf45764559b47fb528bd9aa66676 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 18 Nov 2016 11:48:09 +0900 Subject: [PATCH] Expose Tomcat's accesslog requestAttributesEnabled This commit adds an extra property to the `server.tomcat.accesslog` to control the `reqestAttributesEnabled` flag. This flag sets request attributes for IP address, Hostname, protocol and port used for the request. Closes gh-7367 --- .../boot/autoconfigure/web/ServerProperties.java | 16 ++++++++++++++++ .../autoconfigure/web/ServerPropertiesTests.java | 2 ++ .../appendix-application-properties.adoc | 1 + 3 files changed, 19 insertions(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 902fdb7ddf..9f9c4afeef 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -912,6 +912,8 @@ public class ServerProperties valve.setPrefix(this.accesslog.getPrefix()); valve.setSuffix(this.accesslog.getSuffix()); valve.setRenameOnRotate(this.accesslog.isRenameOnRotate()); + valve.setRequestAttributesEnabled( + this.accesslog.isRequestAttributesEnabled()); factory.addEngineValves(valve); } @@ -961,6 +963,12 @@ public class ServerProperties */ private boolean renameOnRotate; + /** + * Set request attributes for IP address, Hostname, protocol and port used + * for the request. + */ + private boolean requestAttributesEnabled; + public boolean isEnabled() { return this.enabled; } @@ -1009,6 +1017,14 @@ public class ServerProperties this.renameOnRotate = renameOnRotate; } + public boolean isRequestAttributesEnabled() { + return this.requestAttributesEnabled; + } + + public void setRequestAttributesEnabled(boolean requestAttributesEnabled) { + this.requestAttributesEnabled = requestAttributesEnabled; + } + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 177c5f2dda..7a76eaffea 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -137,6 +137,7 @@ public class ServerPropertiesTests { map.put("server.tomcat.accesslog.pattern", "%h %t '%r' %s %b"); map.put("server.tomcat.accesslog.prefix", "foo"); map.put("server.tomcat.accesslog.rename-on-rotate", "true"); + map.put("server.tomcat.accesslog.request-attributes-enabled", "true"); map.put("server.tomcat.accesslog.suffix", "-bar.log"); map.put("server.tomcat.protocol_header", "X-Forwarded-Protocol"); map.put("server.tomcat.remote_ip_header", "Remote-Ip"); @@ -147,6 +148,7 @@ public class ServerPropertiesTests { assertThat(tomcat.getAccesslog().getPattern()).isEqualTo("%h %t '%r' %s %b"); assertThat(tomcat.getAccesslog().getPrefix()).isEqualTo("foo"); assertThat(tomcat.getAccesslog().isRenameOnRotate()).isTrue(); + assertThat(tomcat.getAccesslog().isRequestAttributesEnabled()).isTrue(); assertThat(tomcat.getAccesslog().getSuffix()).isEqualTo("-bar.log"); assertThat(tomcat.getRemoteIpHeader()).isEqualTo("Remote-Ip"); assertThat(tomcat.getProtocolHeader()).isEqualTo("X-Forwarded-Protocol"); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index aa7e059b46..86e3ac92bb 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -198,6 +198,7 @@ content into your application; rather pick only the properties that you need. server.tomcat.accesslog.pattern=common # Format pattern for access logs. server.tomcat.accesslog.prefix=access_log # Log file name prefix. server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time. + server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for IP address, Hostname, protocol and port used for the request. server.tomcat.accesslog.suffix=.log # Log file name suffix. server.tomcat.background-processor-delay=30 # Delay in seconds between the invocation of backgroundProcess methods. server.tomcat.basedir= # Tomcat base directory. If not specified a temporary directory will be used.