From e233ea7f546fcbc5fccf972bc70c26373103444c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Thu, 3 Dec 2015 12:21:37 +0100 Subject: [PATCH 1/2] Fix undertow access_log file name Undertow 1.3.2 changed the default access log file suffix from '.log' to just 'log'. Thus we need to adapt the file name pattern to include the missing dot. Closes gh-4670 --- .../undertow/UndertowEmbeddedServletContainerFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java index ef914ca869a..812a3a69eea 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java @@ -384,7 +384,7 @@ public class UndertowEmbeddedServletContainerFactory try { createAccessLogDirectoryIfNecessary(); AccessLogReceiver accessLogReceiver = new DefaultAccessLogReceiver( - createWorker(), this.accessLogDirectory, "access_log"); + createWorker(), this.accessLogDirectory, "access_log."); String formatString = (this.accessLogPattern != null) ? this.accessLogPattern : "common"; return new AccessLogHandler(handler, accessLogReceiver, formatString, From 753341c9ffa65f24cef5ee96d138e24840680a10 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 3 Dec 2015 12:44:11 +0000 Subject: [PATCH 2/2] Add a test for enabling Undertow's access log and verify the file name See gh-4670 --- ...wEmbeddedServletContainerFactoryTests.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java index a06904b875b..9a1695c7452 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java @@ -16,6 +16,9 @@ package org.springframework.boot.context.embedded.undertow; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -39,6 +42,8 @@ import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.http.HttpStatus; import org.springframework.test.util.ReflectionTestUtils; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; @@ -172,6 +177,21 @@ public class UndertowEmbeddedServletContainerFactoryTests is(not(equalTo(getServletContainerFromNewFactory())))); } + @Test + public void accessLogCanBeEnabled() throws IOException, URISyntaxException { + UndertowEmbeddedServletContainerFactory factory = getFactory(); + factory.setAccessLogEnabled(true); + File accessLogDirectory = this.temporaryFolder.getRoot(); + factory.setAccessLogDirectory(accessLogDirectory); + assertThat(accessLogDirectory.listFiles(), is(arrayWithSize(0))); + this.container = factory.getEmbeddedServletContainer( + new ServletRegistrationBean(new ExampleServlet(), "/hello")); + this.container.start(); + assertThat(getResponse(getLocalUrl("/hello")), equalTo("Hello World")); + assertThat(accessLogDirectory.listFiles(), + is(arrayContaining(new File(accessLogDirectory, "access_log.log")))); + } + @Override protected Object getJspServlet() { return null; // Undertow does not support JSPs