Skip to content

Commit a22ba0f

Browse files
committed
Merge pull request #15954 from nosan
* pr/15954: Polish "Expose Tomcat AccessLog Max days property" Expose Tomcat AccessLog Max days property
2 parents be40d00 + 71df2f3 commit a22ba0f

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -593,6 +593,11 @@ public static class Accesslog {
593593
*/
594594
private boolean renameOnRotate = false;
595595

596+
/**
597+
* Number of days to retain the access log files before they are removed.
598+
*/
599+
private int maxDays = -1;
600+
596601
/**
597602
* Date format to place in the log file name.
598603
*/
@@ -665,6 +670,14 @@ public void setRenameOnRotate(boolean renameOnRotate) {
665670
this.renameOnRotate = renameOnRotate;
666671
}
667672

673+
public int getMaxDays() {
674+
return this.maxDays;
675+
}
676+
677+
public void setMaxDays(int maxDays) {
678+
this.maxDays = maxDays;
679+
}
680+
668681
public String getFileDateFormat() {
669682
return this.fileDateFormat;
670683
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -258,6 +258,7 @@ private void customizeAccessLog(ConfigurableTomcatWebServerFactory factory) {
258258
valve.setPrefix(tomcatProperties.getAccesslog().getPrefix());
259259
valve.setSuffix(tomcatProperties.getAccesslog().getSuffix());
260260
valve.setRenameOnRotate(tomcatProperties.getAccesslog().isRenameOnRotate());
261+
valve.setMaxDays(tomcatProperties.getAccesslog().getMaxDays());
261262
valve.setFileDateFormat(tomcatProperties.getAccesslog().getFileDateFormat());
262263
valve.setRequestAttributesEnabled(
263264
tomcatProperties.getAccesslog().isRequestAttributesEnabled());

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -325,6 +325,24 @@ public void accessLogIsDisabledByDefault() {
325325
assertThat(factory.getEngineValves()).isEmpty();
326326
}
327327

328+
@Test
329+
public void accessLogMaxDaysDefault() {
330+
bind("server.tomcat.accesslog.enabled=true");
331+
TomcatServletWebServerFactory factory = customizeAndGetFactory();
332+
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
333+
.getMaxDays()).isEqualTo(
334+
this.serverProperties.getTomcat().getAccesslog().getMaxDays());
335+
}
336+
337+
@Test
338+
public void accessLoMaxDaysCanBeRedefined() {
339+
bind("server.tomcat.accesslog.enabled=true",
340+
"server.tomcat.accesslog.max-days=20");
341+
TomcatServletWebServerFactory factory = customizeAndGetFactory();
342+
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
343+
.getMaxDays()).isEqualTo(20);
344+
}
345+
328346
private void bind(String... inlinedProperties) {
329347
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
330348
inlinedProperties);

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix/application-properties.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ content into your application. Rather, pick only the properties that you need.
255255
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be absolute or relative to the Tomcat base dir.
256256
server.tomcat.accesslog.enabled=false # Enable access log.
257257
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in the log file name.
258+
server.tomcat.accesslog.max-days=-1# Number of days to retain the access log files before they are removed.
258259
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
259260
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
260261
server.tomcat.accesslog.rename-on-rotate=false # Whether to defer inclusion of the date stamp in the file name until rotate time.

0 commit comments

Comments
 (0)