From 6c7a5c5077d624e85f6db4d870735888f479cc41 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 5 Aug 2015 14:33:14 +0200 Subject: [PATCH] Harmonize Undertow's access log properties Harmonize the configuration properties for Undertow to match the changes made for gh-2491. Move `spring.undertow.accessLog*` to `spring.undertow.accesslog.*` --- .../autoconfigure/web/ServerProperties.java | 125 ++++++++++++++---- .../appendix-application-properties.adoc | 6 +- .../src/main/resources/application.properties | 6 +- 3 files changed, 107 insertions(+), 30 deletions(-) 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 ec882f81fe..b64c6299f8 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 @@ -467,7 +467,7 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord public static class Tomcat { /** - * Access log configuration + * Access log configuration. */ private final Accesslog accesslog = new Accesslog(); @@ -846,20 +846,7 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord */ private Boolean directBuffers; - /** - * Format pattern for access logs. - */ - private String accessLogPattern = "common"; - - /** - * Enable access log. - */ - private boolean accessLogEnabled = false; - - /** - * Undertow access log directory. - */ - private File accessLogDir = new File("logs"); + private final Accesslog accesslog = new Accesslog(); public Integer getBufferSize() { return this.bufferSize; @@ -901,28 +888,74 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord this.directBuffers = directBuffers; } + /** + * Access log configuration. + */ + public Accesslog getAccesslog() { + return accesslog; + } + + /** + * Get the format pattern for access logs. + * @return the format pattern for access logs + * @deprecated since 1.3.0 in favor of {@code server.undertow.accesslog.pattern} + */ + @Deprecated + @DeprecatedConfigurationProperty(replacement = "server.undertow.accesslog.pattern") public String getAccessLogPattern() { - return this.accessLogPattern; + return this.accesslog.getPattern(); } + /** + * Set the format pattern for access logs + * @param accessLogPattern the pattern for access logs + * @deprecated since 1.3.0 in favor of {@code server.undertow.accesslog.pattern} + */ + @Deprecated public void setAccessLogPattern(String accessLogPattern) { - this.accessLogPattern = accessLogPattern; + this.accesslog.setPattern(accessLogPattern); } + /** + * Specify if access log is enabled. + * @return {@code true} if access log is enabled + * @deprecated since 1.3.0 in favor of {@code server.undertow.accesslog.enabled} + */ + @Deprecated + @DeprecatedConfigurationProperty(replacement = "server.undertow.accesslog.enabled") public boolean isAccessLogEnabled() { - return this.accessLogEnabled; + return this.accesslog.isEnabled(); } + /** + * Set if access log is enabled. + * @param accessLogEnabled the access log enable flag + * @deprecated since 1.3.0 in favor of {@code server.undertow.accesslog.enabled} + */ + @Deprecated public void setAccessLogEnabled(boolean accessLogEnabled) { - this.accessLogEnabled = accessLogEnabled; + getAccesslog().setEnabled(accessLogEnabled); } + /** + * Get the access log directory. + * @return the access log directory + * @deprecated since 1.3.0 in favor of {@code server.undertow.accesslog.dir} + */ + @Deprecated + @DeprecatedConfigurationProperty(replacement = "server.undertow.accesslog.dir") public File getAccessLogDir() { - return this.accessLogDir; + return this.accesslog.getDir(); } + /** + * Set the access log directory. + * @param accessLogDir the access log directory + * @deprecated since 1.3.0 in favor of {@code server.tomcat.accesslog.dir} + */ + @Deprecated public void setAccessLogDir(File accessLogDir) { - this.accessLogDir = accessLogDir; + getAccesslog().setDir(accessLogDir); } void customizeUndertow(UndertowEmbeddedServletContainerFactory factory) { @@ -931,9 +964,53 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord factory.setIoThreads(this.ioThreads); factory.setWorkerThreads(this.workerThreads); factory.setDirectBuffers(this.directBuffers); - factory.setAccessLogDirectory(this.accessLogDir); - factory.setAccessLogPattern(this.accessLogPattern); - factory.setAccessLogEnabled(this.accessLogEnabled); + factory.setAccessLogDirectory(this.accesslog.dir); + factory.setAccessLogPattern(this.accesslog.pattern); + factory.setAccessLogEnabled(this.accesslog.enabled); + } + + + public static class Accesslog { + + /** + * Enable access log. + */ + private boolean enabled = false; + + /** + * Format pattern for access logs. + */ + private String pattern = "common"; + + /** + * Undertow access log directory. + */ + private File dir = new File("logs"); + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getPattern() { + return pattern; + } + + public void setPattern(String pattern) { + this.pattern = pattern; + } + + public File getDir() { + return dir; + } + + public void setDir(File dir) { + this.dir = dir; + } + } } 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 f6d38fa598..656ba4fad1 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -126,9 +126,9 @@ content into your application; rather pick only the properties that you need. server.tomcat.max-http-header-size= # maximum size in bytes of the HTTP message header server.tomcat.max-threads = 0 # number of threads in protocol handler server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding - server.undertow.access-log-enabled=false # if access logging is enabled - server.undertow.access-log-pattern=common # log pattern of the access log - server.undertow.access-log-dir=logs # access logs directory + server.undertow.accesslog.enabled=false # if access logging is enabled + server.undertow.accesslog.pattern=common # log pattern of the access log + server.undertow.accesslog.dir=logs # access logs directory server.undertow.buffer-size= # size of each buffer in bytes server.undertow.buffers-per-region= # number of buffer per region server.undertow.direct-buffers=false # allocate buffers outside the Java heap diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-undertow/src/main/resources/application.properties index 5b074bf346..bb809f2a9c 100644 --- a/spring-boot-samples/spring-boot-sample-undertow/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-undertow/src/main/resources/application.properties @@ -1,5 +1,5 @@ -server.undertow.access-log-enabled=true -server.undertow.access-log-dir=target/logs -server.undertow.access-log-pattern=combined +server.undertow.accesslog.enabled=true +server.undertow.accesslog.dir=target/logs +server.undertow.accesslog.pattern=combined server.compression.enabled=true server.compression.min-response-size=1 \ No newline at end of file