Skip to content

Commit

Permalink
Expose Tomcat AccessLog Max days property
Browse files Browse the repository at this point in the history
  • Loading branch information
nosan authored and snicoll committed Feb 14, 2019
1 parent be40d00 commit 596f0c2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,19 @@ public static class Accesslog {
*/
private boolean buffered = true;

/**
* The number of days to retain the access log files before they are removed.
*/
private int maxDays = -1;

public int getMaxDays() {
return this.maxDays;
}

public void setMaxDays(int maxDays) {
this.maxDays = maxDays;
}

public boolean isEnabled() {
return this.enabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ private void customizeAccessLog(ConfigurableTomcatWebServerFactory factory) {
tomcatProperties.getAccesslog().isRequestAttributesEnabled());
valve.setRotatable(tomcatProperties.getAccesslog().isRotate());
valve.setBuffered(tomcatProperties.getAccesslog().isBuffered());
valve.setMaxDays(tomcatProperties.getAccesslog().getMaxDays());
factory.addEngineValves(valve);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,23 @@ public void accessLogIsDisabledByDefault() {
assertThat(factory.getEngineValves()).isEmpty();
}

@Test
public void accessLogSetMaxDays() {
bind("server.tomcat.accesslog.enabled=true",
"server.tomcat.accesslog.max-days=20");
TomcatServletWebServerFactory factory = customizeAndGetFactory();
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
.getMaxDays()).isEqualTo(20);
}

@Test
public void accessLogDefaultMaxDays() {
bind("server.tomcat.accesslog.enabled=true");
TomcatServletWebServerFactory factory = customizeAndGetFactory();
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
.getMaxDays()).isEqualTo(-1);
}

private void bind(String... inlinedProperties) {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
inlinedProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ content into your application. Rather, pick only the properties that you need.
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be absolute or relative to the Tomcat base dir.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in the log file name.
server.tomcat.accesslog.max-days=-1#The number of days to retain the access log files before they are removed.
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 # Whether to defer inclusion of the date stamp in the file name until rotate time.
Expand Down

0 comments on commit 596f0c2

Please sign in to comment.