From 8f4cdf1c832acad81e2133158c792e53b1a5f3f8 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 6 Jun 2019 20:44:41 +1000 Subject: [PATCH] upgrade log4j2 version and fix log4j2.xml provided sample (#3721) * upgrade log4j2 version and fix log4j2.xml provided sample, add disruptor if users wants to use async logging Signed-off-by: olivier lamy --- .../src/main/config/modules/log4j2-api.mod | 3 +- .../src/main/config/modules/log4j2-impl.mod | 1 + .../modules/log4j2-impl/resources/log4j2.xml | 37 +++++++++------- pom.xml | 3 +- .../tests/distribution/DistributionTests.java | 44 +++++++++++++++++++ 5 files changed, 70 insertions(+), 18 deletions(-) diff --git a/jetty-util/src/main/config/modules/log4j2-api.mod b/jetty-util/src/main/config/modules/log4j2-api.mod index dc6a88202e8..f9766f6f531 100644 --- a/jetty-util/src/main/config/modules/log4j2-api.mod +++ b/jetty-util/src/main/config/modules/log4j2-api.mod @@ -23,5 +23,6 @@ Log4j is released under the Apache 2.0 license. http://www.apache.org/licenses/LICENSE-2.0.html [ini] -log4j2.version?=2.11.1 +log4j2.version?=2.11.2 +disruptor.version=3.4.2 jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/log4j2/ diff --git a/jetty-util/src/main/config/modules/log4j2-impl.mod b/jetty-util/src/main/config/modules/log4j2-impl.mod index d95806e7c54..d8997d971db 100644 --- a/jetty-util/src/main/config/modules/log4j2-impl.mod +++ b/jetty-util/src/main/config/modules/log4j2-impl.mod @@ -19,6 +19,7 @@ log4j2-impl [files] maven://org.apache.logging.log4j/log4j-core/${log4j2.version}|lib/log4j2/log4j-core-${log4j2.version}.jar +maven://com.lmax/disruptor/${disruptor.version}|lib/log4j2/disruptor-${disruptor.version}.jar basehome:modules/log4j2-impl [lib] diff --git a/jetty-util/src/main/config/modules/log4j2-impl/resources/log4j2.xml b/jetty-util/src/main/config/modules/log4j2-impl/resources/log4j2.xml index 9fa555d3d68..400c779cb5c 100644 --- a/jetty-util/src/main/config/modules/log4j2-impl/resources/log4j2.xml +++ b/jetty-util/src/main/config/modules/log4j2-impl/resources/log4j2.xml @@ -1,13 +1,9 @@ - - - - - - - + + ${sys:jetty.logging.dir:-logs} + @@ -16,24 +12,33 @@ - + + + + + + + + diff --git a/pom.xml b/pom.xml index 638f85e4ca8..8975f8f0398 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,8 @@ UTF-8 1.4 1.7.25 - 2.11.1 + 2.11.2 + 3.4.2 1.2.3 1.2 1.1.3.v20160715 diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java index 8b9c5f45900..be43ce4f4fb 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.http2.client.HTTP2Client; import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2; import org.eclipse.jetty.unixsocket.UnixSocketConnector; import org.eclipse.jetty.unixsocket.client.HttpClientTransportOverUnixSockets; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnJre; @@ -265,4 +266,47 @@ public class DistributionTests extends AbstractDistributionTest Files.deleteIfExists(sockFile); } } + + @Test + public void testLog4j2ModuleWithSimpleWebAppWithJSP() throws Exception + { + Path jettyBase = Files.createTempDirectory( "jetty_base"); + String jettyVersion = System.getProperty("jettyVersion"); + DistributionTester distribution = DistributionTester.Builder.newInstance() + .jettyVersion(jettyVersion) + .jettyBase(jettyBase) + .mavenLocalRepository(System.getProperty("mavenRepoPath")) + .build(); + + String[] args1 = { + "--create-startd", + "--approve-all-licenses", + "--add-to-start=resources,server,http,webapp,deploy,jsp,servlet,servlets,logging-log4j2" + }; + try (DistributionTester.Run run1 = distribution.start(args1)) + { + assertTrue(run1.awaitFor(5, TimeUnit.SECONDS)); + assertEquals(0, run1.getExitValue()); + assertTrue(Files.exists(jettyBase.resolve("resources/log4j2.xml"))); + + File war = distribution.resolveArtifact("org.eclipse.jetty.tests:test-simple-webapp:war:" + jettyVersion); + distribution.installWarFile(war, "test"); + + int port = distribution.freePort(); + try (DistributionTester.Run run2 = distribution.start("jetty.http.port=" + port)) + { + assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS)); + + startHttpClient(); + ContentResponse response = client.GET("http://localhost:" + port + "/test/index.jsp"); + assertEquals(HttpStatus.OK_200, response.getStatus()); + assertThat(response.getContentAsString(), containsString("Hello")); + assertThat(response.getContentAsString(), not(containsString("<%"))); + assertTrue(Files.exists(jettyBase.resolve("resources/log4j2.xml"))); + } + } finally + { + IO.delete(jettyBase.toFile()); + } + } }