Merge pull request #15954 from nosan

* pr/15954:
  Polish "Expose Tomcat AccessLog Max days property"
  Expose Tomcat AccessLog Max days property
pull/15958/head
Stephane Nicoll 6 years ago
commit a22ba0f801

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -593,6 +593,11 @@ public class ServerProperties {
*/
private boolean renameOnRotate = false;
/**
* Number of days to retain the access log files before they are removed.
*/
private int maxDays = -1;
/**
* Date format to place in the log file name.
*/
@ -665,6 +670,14 @@ public class ServerProperties {
this.renameOnRotate = renameOnRotate;
}
public int getMaxDays() {
return this.maxDays;
}
public void setMaxDays(int maxDays) {
this.maxDays = maxDays;
}
public String getFileDateFormat() {
return this.fileDateFormat;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -258,6 +258,7 @@ public class TomcatWebServerFactoryCustomizer implements
valve.setPrefix(tomcatProperties.getAccesslog().getPrefix());
valve.setSuffix(tomcatProperties.getAccesslog().getSuffix());
valve.setRenameOnRotate(tomcatProperties.getAccesslog().isRenameOnRotate());
valve.setMaxDays(tomcatProperties.getAccesslog().getMaxDays());
valve.setFileDateFormat(tomcatProperties.getAccesslog().getFileDateFormat());
valve.setRequestAttributesEnabled(
tomcatProperties.getAccesslog().isRequestAttributesEnabled());

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -325,6 +325,24 @@ public class TomcatWebServerFactoryCustomizerTests {
assertThat(factory.getEngineValves()).isEmpty();
}
@Test
public void accessLogMaxDaysDefault() {
bind("server.tomcat.accesslog.enabled=true");
TomcatServletWebServerFactory factory = customizeAndGetFactory();
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
.getMaxDays()).isEqualTo(
this.serverProperties.getTomcat().getAccesslog().getMaxDays());
}
@Test
public void accessLoMaxDaysCanBeRedefined() {
bind("server.tomcat.accesslog.enabled=true",
"server.tomcat.accesslog.max-days=20");
TomcatServletWebServerFactory factory = customizeAndGetFactory();
assertThat(((AccessLogValve) factory.getEngineValves().iterator().next())
.getMaxDays()).isEqualTo(20);
}
private void bind(String... inlinedProperties) {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
inlinedProperties);

@ -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# 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.

Loading…
Cancel
Save