Skip to content

Commit 71df2f3

Browse files
committed
Polish "Expose Tomcat AccessLog Max days property"
Closes gh-15954
1 parent 596f0c2 commit 71df2f3

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

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

Lines changed: 14 additions & 14 deletions
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
*/
@@ -609,19 +614,6 @@ public static class Accesslog {
609614
*/
610615
private boolean buffered = true;
611616

612-
/**
613-
* The number of days to retain the access log files before they are removed.
614-
*/
615-
private int maxDays = -1;
616-
617-
public int getMaxDays() {
618-
return this.maxDays;
619-
}
620-
621-
public void setMaxDays(int maxDays) {
622-
this.maxDays = maxDays;
623-
}
624-
625617
public boolean isEnabled() {
626618
return this.enabled;
627619
}
@@ -678,6 +670,14 @@ public void setRenameOnRotate(boolean renameOnRotate) {
678670
this.renameOnRotate = renameOnRotate;
679671
}
680672

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

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

Lines changed: 2 additions & 2 deletions
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,12 +258,12 @@ 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());
264265
valve.setRotatable(tomcatProperties.getAccesslog().isRotate());
265266
valve.setBuffered(tomcatProperties.getAccesslog().isBuffered());
266-
valve.setMaxDays(tomcatProperties.getAccesslog().getMaxDays());
267267
factory.addEngineValves(valve);
268268
}
269269

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

Lines changed: 9 additions & 8 deletions
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.
@@ -326,20 +326,21 @@ public void accessLogIsDisabledByDefault() {
326326
}
327327

328328
@Test
329-
public void accessLogSetMaxDays() {
330-
bind("server.tomcat.accesslog.enabled=true",
331-
"server.tomcat.accesslog.max-days=20");
329+
public void accessLogMaxDaysDefault() {
330+
bind("server.tomcat.accesslog.enabled=true");
332331
TomcatServletWebServerFactory factory = customizeAndGetFactory();
333332
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
334-
.getMaxDays()).isEqualTo(20);
333+
.getMaxDays()).isEqualTo(
334+
this.serverProperties.getTomcat().getAccesslog().getMaxDays());
335335
}
336336

337337
@Test
338-
public void accessLogDefaultMaxDays() {
339-
bind("server.tomcat.accesslog.enabled=true");
338+
public void accessLoMaxDaysCanBeRedefined() {
339+
bind("server.tomcat.accesslog.enabled=true",
340+
"server.tomcat.accesslog.max-days=20");
340341
TomcatServletWebServerFactory factory = customizeAndGetFactory();
341342
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
342-
.getMaxDays()).isEqualTo(-1);
343+
.getMaxDays()).isEqualTo(20);
343344
}
344345

345346
private void bind(String... inlinedProperties) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +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#The number of days to retain the access log files before they are removed.
258+
server.tomcat.accesslog.max-days=-1# Number of days to retain the access log files before they are removed.
259259
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
260260
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
261261
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)