From fc4d8b99d61d61e79b93b83a0ac8d0cb373c5ee6 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 28 Jun 2016 16:38:01 +0200 Subject: [PATCH] Allow to configure Tomcat's renameOnRotate property Closes gh-5981 --- .../boot/autoconfigure/web/ServerProperties.java | 15 +++++++++++++++ .../autoconfigure/web/ServerPropertiesTests.java | 2 ++ .../asciidoc/appendix-application-properties.adoc | 1 + 3 files changed, 18 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 c4f978ec549..40ea8a3dc45 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 @@ -907,6 +907,7 @@ public class ServerProperties valve.setDirectory(this.accesslog.getDirectory()); valve.setPrefix(this.accesslog.getPrefix()); valve.setSuffix(this.accesslog.getSuffix()); + valve.setRenameOnRotate(this.accesslog.isRenameOnRotate()); factory.addContextValves(valve); } @@ -938,6 +939,11 @@ public class ServerProperties */ private String suffix = ".log"; + /** + * Defer inclusion of the date stamp in the file name until rotate time. + */ + private boolean renameOnRotate; + public boolean isEnabled() { return this.enabled; } @@ -977,6 +983,15 @@ public class ServerProperties public void setSuffix(String suffix) { this.suffix = suffix; } + + public boolean isRenameOnRotate() { + return this.renameOnRotate; + } + + public void setRenameOnRotate(boolean renameOnRotate) { + this.renameOnRotate = renameOnRotate; + } + } } 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 b91a5ad1995..4e609ff193e 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 @@ -133,6 +133,7 @@ public class ServerPropertiesTests { Map map = new HashMap(); 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.suffix", "-bar.log"); map.put("server.tomcat.protocol_header", "X-Forwarded-Protocol"); map.put("server.tomcat.remote_ip_header", "Remote-Ip"); @@ -141,6 +142,7 @@ public class ServerPropertiesTests { ServerProperties.Tomcat tomcat = this.properties.getTomcat(); assertThat(tomcat.getAccesslog().getPattern()).isEqualTo("%h %t '%r' %s %b"); assertThat(tomcat.getAccesslog().getPrefix()).isEqualTo("foo"); + assertThat(tomcat.getAccesslog().isRenameOnRotate()).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 b1f34a86b0a..0188e320075 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.enabled=false # Enable access log. 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.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.