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 <oliver.lamy@gmail.com>
This commit is contained in:
Olivier Lamy 2019-06-06 20:44:41 +10:00 committed by GitHub
parent 03baa6bc9b
commit 8f4cdf1c83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 18 deletions

View File

@ -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/

View File

@ -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]

View File

@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="Jetty" >
<Appenders>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
<properties>
<property name="logging.dir">${sys:jetty.logging.dir:-logs}</property>
</properties>
<Appenders>
<Console name="console" target="SYSTEM_ERR">
@ -16,24 +12,33 @@
</PatternLayout>
</Console>
<!--
<RollingFile name="file"
fileName="${jetty.logging.dir}/jetty.log"
filePattern="${jetty.logging.dir}/jetty-%d{MM-dd-yyyy}.log.gz"
<RollingRandomAccessFile name="file"
fileName="${logging.dir}/jetty.log"
filePattern="${logging.dir}/jetty-%d{MM-dd-yyyy}.log.gz"
ignoreExceptions="false">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n</Pattern>
<Pattern>%d [%t] %-5p %c %x - %m%n</Pattern>
</PatternLayout>
<SizeBasedTriggeringPolicy size="10MB"/>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
-->
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="console"/>
</Root>
<!--
To have all logger async
<AsyncRoot level="info">
<AppenderRef ref="file"/>
</AsyncRoot>
-->
</Loggers>
</Configuration>

View File

@ -20,7 +20,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build-support.version>1.4</build-support.version>
<slf4j.version>1.7.25</slf4j.version>
<log4j2.version>2.11.1</log4j2.version>
<log4j2.version>2.11.2</log4j2.version>
<disruptor.version>3.4.2</disruptor.version>
<logback.version>1.2.3</logback.version>
<jetty-test-policy.version>1.2</jetty-test-policy.version>
<alpn.api.version>1.1.3.v20160715</alpn.api.version>

View File

@ -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());
}
}
}