diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizer.java index 221ac8be1d..ab8f45d60f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizer.java @@ -414,6 +414,7 @@ public class DefaultServletContainerCustomizer valve.setPrefix(tomcatProperties.getAccesslog().getPrefix()); valve.setSuffix(tomcatProperties.getAccesslog().getSuffix()); valve.setRenameOnRotate(tomcatProperties.getAccesslog().isRenameOnRotate()); + valve.setFileDateFormat(tomcatProperties.getAccesslog().getFileDateFormat()); valve.setRequestAttributesEnabled( tomcatProperties.getAccesslog().isRequestAttributesEnabled()); valve.setRotatable(tomcatProperties.getAccesslog().isRotate()); 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 891b3a4676..9162c7bfb9 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 @@ -653,6 +653,11 @@ public class ServerProperties { */ private boolean renameOnRotate; + /** + * Date format to place in log file name. + */ + private String fileDateFormat = ".yyyy-MM-dd"; + /** * Set request attributes for IP address, Hostname, protocol and port used for * the request. @@ -720,6 +725,14 @@ public class ServerProperties { this.renameOnRotate = renameOnRotate; } + public String getFileDateFormat() { + return this.fileDateFormat; + } + + public void setFileDateFormat(String fileDateFormat) { + this.fileDateFormat = fileDateFormat; + } + public boolean isRequestAttributesEnabled() { return this.requestAttributesEnabled; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerTests.java index ad23a0a66f..3d894221c1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerTests.java @@ -93,6 +93,29 @@ public class DefaultServletContainerCustomizerTests { .isInstanceOf(AccessLogValve.class); } + @Test + public void tomcatAccessLogFileDateFormatByDefault() { + TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + Map map = new HashMap(); + map.put("server.tomcat.accesslog.enabled", "true"); + bindProperties(map); + this.customizer.customize(tomcatContainer); + assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + .getFileDateFormat()).isEqualTo(".yyyy-MM-dd"); + } + + @Test + public void tomcatAccessLogFileDateFormatCanBeRedefined() { + TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + Map map = new HashMap(); + map.put("server.tomcat.accesslog.enabled", "true"); + map.put("server.tomcat.accesslog.file-date-format", "yyyy-MM-dd.HH"); + bindProperties(map); + this.customizer.customize(tomcatContainer); + assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + .getFileDateFormat()).isEqualTo("yyyy-MM-dd.HH"); + } + @Test public void tomcatAccessLogIsBufferedByDefault() { TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); 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 85a1eb5258..cf40ee6efd 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -195,6 +195,7 @@ content into your application; rather pick only the properties that you need. server.tomcat.accesslog.buffered=true # Buffer output such that it is only flushed periodically. server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute. server.tomcat.accesslog.enabled=false # Enable access log. + server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in log file name. 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.