Repository: logging-log4j2 Updated Branches: refs/heads/java9NoMultiRelease 34552d7d7 -> 8475d1759
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/main/java/org/apache/logging/log4j/core/net/server/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/main/java/org/apache/logging/log4j/core/net/server/package-info.java b/log4j-server/src/main/java/org/apache/logging/log4j/core/net/server/package-info.java new file mode 100644 index 0000000..0d9d027 --- /dev/null +++ b/log4j-server/src/main/java/org/apache/logging/log4j/core/net/server/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +/** + * Standalone server classes for consuming log events over a network. Each of the various servers should be used with + * another Log4j configuration to handle incoming {@link org.apache.logging.log4j.core.LogEvent}s. It is recommended + * to consider using the <a href="../../../../../../../../../manual/appenders.html#FlumeAppender">Flume Appender</a> + * for highly reliable networked logging. + */ +package org.apache.logging.log4j.core.net.server; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/site/markdown/index.md ---------------------------------------------------------------------- diff --git a/log4j-server/src/site/markdown/index.md b/log4j-server/src/site/markdown/index.md new file mode 100644 index 0000000..b66e935 --- /dev/null +++ b/log4j-server/src/site/markdown/index.md @@ -0,0 +1,29 @@ +<!-- vim: set syn=markdown : --> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +# Log4j Server components + +## Log4j Server components + + +## Requirements + +The Log4j Server components requires the Log4j 2 API and core. This component was introduced in Log4j 2.8.2, +before it was part of log4j-core. For more information, see [Runtime Dependencies](../runtime-dependencies.html). + +## Usage http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/site/site.xml ---------------------------------------------------------------------- diff --git a/log4j-server/src/site/site.xml b/log4j-server/src/site/site.xml new file mode 100644 index 0000000..f863dbf --- /dev/null +++ b/log4j-server/src/site/site.xml @@ -0,0 +1,52 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<project name="Log4j IOStreams" + xmlns="http://maven.apache.org/DECORATION/1.4.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd"> + <body> + <links> + <item name="Apache" href="http://www.apache.org/" /> + <item name="Logging Services" href="http://logging.apache.org/"/> + <item name="Log4j" href="../index.html"/> + </links> + + <!-- Component-specific reports --> + <menu ref="reports"/> + + <!-- Overall Project Info --> + <menu name="Log4j Project Information" img="icon-info-sign"> + <item name="Dependencies" href="../dependencies.html" /> + <item name="Dependency Convergence" href="../dependency-convergence.html" /> + <item name="Dependency Management" href="../dependency-management.html" /> + <item name="Project Team" href="../team-list.html" /> + <item name="Mailing Lists" href="../mail-lists.html" /> + <item name="Issue Tracking" href="../issue-tracking.html" /> + <item name="Project License" href="../license.html" /> + <item name="Source Repository" href="../source-repository.html" /> + <item name="Project Summary" href="../project-summary.html" /> + </menu> + + <menu name="Log4j Project Reports" img="icon-cog"> + <item name="Changes Report" href="../changes-report.html" /> + <item name="JIRA Report" href="../jira-report.html" /> + <item name="Surefire Report" href="../surefire-report.html" /> + <item name="RAT Report" href="../rat-report.html" /> + </menu> + </body> +</project> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java new file mode 100644 index 0000000..7351313 --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java @@ -0,0 +1,237 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.AppenderLoggingException; +import org.apache.logging.log4j.core.appender.ConsoleAppender; +import org.apache.logging.log4j.core.appender.SocketAppender; +import org.apache.logging.log4j.core.layout.JsonLayout; +import org.apache.logging.log4j.core.layout.PatternLayout; +import org.apache.logging.log4j.core.layout.XmlLayout; +import org.apache.logging.log4j.core.net.Protocol; +import org.apache.logging.log4j.test.AvailablePortFinder; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.After; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * + */ +public abstract class AbstractSocketServerTest { + + protected static Thread thread; + + private static final String MESSAGE = "This is test message"; + + private static final String MESSAGE_2 = "This is test message 2"; + + private static final String MESSAGE_WITH_SPECIAL_CHARS = "{This}\n[is]\"n\"a\"\r\ntrue:\n\ttest,\nmessage"; + + static final int PORT_NUM = AvailablePortFinder.getNextAvailable(); + + static final int PORT = PORT_NUM; + + private final LoggerContext ctx = LoggerContext.getContext(false); + + private final boolean expectLengthException; + + protected final int port; + + protected final Protocol protocol; + + private final Logger rootLogger = ctx.getLogger(AbstractSocketServerTest.class.getSimpleName()); + + protected AbstractSocketServerTest(final Protocol protocol, final int port, final boolean expectLengthException) { + this.protocol = protocol; + this.port = port; + this.expectLengthException = expectLengthException; + } + + protected Layout<String> createJsonLayout() { + // @formatter: off + return JsonLayout.newBuilder() + .setLocationInfo(true) + .setProperties(true) + .setPropertiesAsList(false) + .setComplete(false) + .setCompact(false) + .setEventEol(false) + .setIncludeStacktrace(true) + .build(); + // @formatter: on + + //return JsonLayout.createLayout(null, true, true, false, false, false, false, null, null, null, true); + } + + protected abstract Layout<? extends Serializable> createLayout(); + + protected Layout<? extends Serializable> createSerializedLayout() { + return null; + } + + protected Layout<String> createXmlLayout() { + return XmlLayout.createLayout(true, true, false, false, null, true); + } + + @After + public void tearDown() { + final Map<String, Appender> map = rootLogger.getAppenders(); + for (final Map.Entry<String, Appender> entry : map.entrySet()) { + final Appender appender = entry.getValue(); + rootLogger.removeAppender(appender); + appender.stop(); + } + } + + @Test + @Ignore("Broken test?") + public void test1000ShortMessages() throws Exception { + testServer(1000); + } + + @Test + @Ignore("Broken test?") + public void test100ShortMessages() throws Exception { + testServer(100); + } + + @Test + public void test10ShortMessages() throws Exception { + testServer(10); + } + + @Test + public void test1ShortMessages() throws Exception { + testServer(1); + } + + @Test + public void test2ShortMessages() throws Exception { + testServer(2); + } + + @Test + public void test64KBMessages() throws Exception { + final char[] a64K = new char[1024 * 64]; + Arrays.fill(a64K, 'a'); + final String m1 = new String(a64K); + final String m2 = MESSAGE_2 + m1; + if (expectLengthException) { + try { + testServer(m1, m2); + } catch (final AppenderLoggingException are) { + assertTrue("", are.getCause() != null && are.getCause() instanceof IOException); + // Failure expected. + } + } else { + testServer(m1, m2); + } + } + + + @Test + public void testMessagesWithSpecialChars() throws Exception { + testServer(MESSAGE_WITH_SPECIAL_CHARS); + } + + + private void testServer(final int size) throws Exception { + final String[] messages = new String[size]; + for (int i = 0; i < messages.length; i++) { + messages[i] = MESSAGE + " " + i; + } + testServer(messages); + } + + protected void testServer(final String... messages) throws Exception { + final Filter socketFilter = new ThreadNameFilter(Filter.Result.NEUTRAL, Filter.Result.DENY); + final Filter serverFilter = new ThreadNameFilter(Filter.Result.DENY, Filter.Result.NEUTRAL); + final Layout<? extends Serializable> socketLayout = createLayout(); + final SocketAppender socketAppender = createSocketAppender(socketFilter, socketLayout); + socketAppender.start(); + final ListAppender listAppender = new ListAppender("Events", serverFilter, null, false, false); + listAppender.start(); + final PatternLayout layout = PatternLayout.newBuilder().withPattern("%m %ex%n").build(); + final ConsoleAppender console = ConsoleAppender.createDefaultAppenderForLayout(layout); + final Logger serverLogger = ctx.getLogger(this.getClass().getName()); + serverLogger.addAppender(console); + serverLogger.setAdditive(false); + + // set appender on root and set level to debug + rootLogger.addAppender(socketAppender); + rootLogger.addAppender(listAppender); + rootLogger.setAdditive(false); + rootLogger.setLevel(Level.DEBUG); + for (final String message : messages) { + rootLogger.debug(message); + } + final int MAX_TRIES = 400; + for (int i = 0; i < MAX_TRIES; i++) { + if (listAppender.getEvents().size() < messages.length) { + try { + // Let the server-side read the messages. + Thread.sleep(50); + } catch (final Exception e) { + e.printStackTrace(); + } + } else { + break; + } + } + final List<LogEvent> events = listAppender.getEvents(); + assertNotNull("No event retrieved", events); + assertEquals("Incorrect number of events received", messages.length, events.size()); + for (int i = 0; i < messages.length; i++) { + assertTrue("Incorrect event", events.get(i).getMessage().getFormattedMessage().equals(messages[i])); + } + } + + protected SocketAppender createSocketAppender(final Filter socketFilter, + final Layout<? extends Serializable> socketLayout) { + // @formatter:off + return SocketAppender.newBuilder() + .withProtocol(this.protocol) + .withHost("localhost") + .withPort(this.port) + .withReconnectDelayMillis(-1) + .withName("test") + .withImmediateFlush(true) + .withImmediateFail(false) + .withIgnoreExceptions(false) + .withLayout(socketLayout) + .withFilter(socketFilter) + .build(); + // @formatter:on + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java new file mode 100644 index 0000000..8ca07a4 --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/SslXmlSocketServerTest.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; +import java.nio.charset.Charset; + +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.SocketAppender; +import org.apache.logging.log4j.core.net.Protocol; +import org.apache.logging.log4j.core.net.ssl.KeyStoreConfiguration; +import org.apache.logging.log4j.core.net.ssl.SslConfiguration; +import org.apache.logging.log4j.core.net.ssl.StoreConfigurationException; +import org.apache.logging.log4j.core.net.ssl.TestConstants; +import org.apache.logging.log4j.core.net.ssl.TrustStoreConfiguration; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class SslXmlSocketServerTest extends AbstractSocketServerTest { + + private static TcpSocketServer<InputStream> server; + + private static SslConfiguration sslConfiguration; + + private static void initServerSocketFactory() throws StoreConfigurationException { + final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, + TestConstants.KEYSTORE_PWD, TestConstants.KEYSTORE_TYPE, null); + final TrustStoreConfiguration tsc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, + TestConstants.TRUSTSTORE_PWD, null, null); + sslConfiguration = SslConfiguration.createSSLConfiguration(null, ksc, tsc); + } + + @Override + protected SocketAppender createSocketAppender(final Filter socketFilter, + final Layout<? extends Serializable> socketLayout) { + // @formatter:off + return SocketAppender.newBuilder() + .withProtocol(this.protocol) + .withHost("localhost") + .withPort(this.port) + .withReconnectDelayMillis(-1) + .withName("test") + .withImmediateFlush(true) + .withImmediateFail(false) + .withIgnoreExceptions(false) + .withLayout(socketLayout) + .withFilter(socketFilter) + .withSslConfiguration(sslConfiguration) + .build(); + // @formatter:on + } + + @BeforeClass + public static void setupClass() throws Exception { + (LoggerContext.getContext(false)).reconfigure(); + initServerSocketFactory(); + // Use a large buffer just to test the code, the UDP test uses a tiny buffer + server = new SecureTcpSocketServer<>(PORT_NUM, new XmlInputStreamLogEventBridge(1024 * 100, + Charset.defaultCharset()), sslConfiguration); + thread = server.startNewThread(); + } + + @AfterClass + public static void tearDownClass() { + try { + server.shutdown(); + } catch (final IOException e) { + e.printStackTrace(); + } + try { + thread.join(); + } catch (final InterruptedException e) { + // ignore + } + } + + public SslXmlSocketServerTest() { + super(Protocol.SSL, PORT, false); + } + + @Override + protected Layout<String> createLayout() { + return super.createXmlLayout(); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java new file mode 100644 index 0000000..6420e7e --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpJsonSocketServerTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.net.Protocol; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class TcpJsonSocketServerTest extends AbstractSocketServerTest { + + private static TcpSocketServer<InputStream> server; + + @BeforeClass + public static void setupClass() throws Exception { + (LoggerContext.getContext(false)).reconfigure(); + server = TcpSocketServer.createJsonSocketServer(PORT_NUM); + thread = server.startNewThread(); + } + + @AfterClass + public static void tearDownClass() { + try { + server.shutdown(); + } catch (final IOException e) { + e.printStackTrace(); + } + try { + thread.join(); + } catch (final InterruptedException e) { + // ignore + } + } + + public TcpJsonSocketServerTest() { + super(Protocol.TCP, PORT, false); + } + + @Override + protected Layout<String> createLayout() { + return super.createJsonLayout(); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java new file mode 100644 index 0000000..645701b --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpSerializedSocketServerTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; + +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.net.Protocol; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class TcpSerializedSocketServerTest extends AbstractSocketServerTest { + + private static TcpSocketServer<ObjectInputStream> server; + + @BeforeClass + public static void setupClass() throws Exception { + (LoggerContext.getContext(false)).reconfigure(); + server = TcpSocketServer.createSerializedSocketServer(PORT_NUM); + thread = server.startNewThread(); + } + + @AfterClass + public static void tearDownClass() { + try { + server.shutdown(); + } catch (final IOException e) { + e.printStackTrace(); + } + try { + thread.join(); + } catch (final InterruptedException e) { + // ignore + } + } + + public TcpSerializedSocketServerTest() { + super(Protocol.TCP, PORT, false); + } + + @Override + protected Layout<? extends Serializable> createLayout() { + return super.createSerializedLayout(); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java new file mode 100644 index 0000000..2290cbd --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/TcpXmlSocketServerTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; + +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.net.Protocol; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class TcpXmlSocketServerTest extends AbstractSocketServerTest { + + private static TcpSocketServer<InputStream> server; + + @BeforeClass + public static void setupClass() throws Exception { + (LoggerContext.getContext(false)).reconfigure(); + // Use a large buffer just to test the code, the UDP test uses a tiny buffer + server = new TcpSocketServer<>(PORT_NUM, new XmlInputStreamLogEventBridge(1024 * 100, + Charset.defaultCharset())); + thread = server.startNewThread(); + } + + @AfterClass + public static void tearDownClass() { + try { + server.shutdown(); + } catch (final IOException e) { + e.printStackTrace(); + } + try { + thread.join(); + } catch (final InterruptedException e) { + // ignore + } + } + + public TcpXmlSocketServerTest() { + super(Protocol.TCP, PORT, false); + } + + @Override + protected Layout<String> createLayout() { + return super.createXmlLayout(); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadIdFilter.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadIdFilter.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadIdFilter.java new file mode 100644 index 0000000..49a9595 --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadIdFilter.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +package org.apache.logging.log4j.core.net.server; + +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.filter.AbstractFilter; + +/** + * TODO Should use thread ID cache? + * @since 2.6 + */ +public class ThreadIdFilter extends AbstractFilter { + + private static final long serialVersionUID = 1L; + + public ThreadIdFilter(final Result onMatch, final Result onMismatch) { + super(onMatch, onMismatch); + } + + @Override + public Filter.Result filter(final LogEvent event) { + return event.getThreadId() == Thread.currentThread().getId() ? onMatch : onMismatch; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadNameFilter.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadNameFilter.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadNameFilter.java new file mode 100644 index 0000000..6f6fb13 --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadNameFilter.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +package org.apache.logging.log4j.core.net.server; + +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.filter.AbstractFilter; + +/** + * TODO Should use thread name cache? + */ +public class ThreadNameFilter extends AbstractFilter { + + private static final long serialVersionUID = 1L; + + public ThreadNameFilter(final Result onMatch, final Result onMismatch) { + super(onMatch, onMismatch); + } + + @Override + public Filter.Result filter(final LogEvent event) { + return event.getThreadName().equals(Thread.currentThread().getName()) ? onMatch : onMismatch; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadPriorityFilter.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadPriorityFilter.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadPriorityFilter.java new file mode 100644 index 0000000..27ecc7d --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/ThreadPriorityFilter.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ + +package org.apache.logging.log4j.core.net.server; + +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.filter.AbstractFilter; + +/** + * TODO Should use thread priority cache? + * @since 2.6 + */ +public class ThreadPriorityFilter extends AbstractFilter { + + private static final long serialVersionUID = 1L; + + public ThreadPriorityFilter(final Result onMatch, final Result onMismatch) { + super(onMatch, onMismatch); + } + + @Override + public Filter.Result filter(final LogEvent event) { + return event.getThreadPriority() == Thread.currentThread().getPriority() ? onMatch : onMismatch; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java new file mode 100644 index 0000000..3f33b14 --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpJsonSocketServerTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.InputStream; +import java.io.Serializable; + +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.net.Protocol; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class UdpJsonSocketServerTest extends AbstractSocketServerTest { + + private static UdpSocketServer<InputStream> server; + + @BeforeClass + public static void setupClass() throws Exception { + (LoggerContext.getContext(false)).reconfigure(); + server = UdpSocketServer.createJsonSocketServer(PORT_NUM); + thread = server.startNewThread(); + } + + @AfterClass + public static void tearDownClass() { + server.shutdown(); + try { + thread.join(); + } catch (final InterruptedException e) { + // ignore + } + } + + public UdpJsonSocketServerTest() { + super(Protocol.UDP, PORT, true); + } + + @Override + protected Layout<? extends Serializable> createLayout() { + return super.createJsonLayout(); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java new file mode 100644 index 0000000..3e7ecad --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpSerializedSocketServerTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.ObjectInputStream; +import java.io.Serializable; + +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.net.Protocol; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; + +@Ignore +public class UdpSerializedSocketServerTest extends AbstractSocketServerTest { + + private static UdpSocketServer<ObjectInputStream> server; + + @BeforeClass + public static void setupClass() throws Exception { + (LoggerContext.getContext(false)).reconfigure(); + server = UdpSocketServer.createSerializedSocketServer(PORT_NUM); + thread = server.startNewThread(); + } + + @AfterClass + public static void tearDownClass() { + server.shutdown(); + try { + thread.join(); + } catch (final InterruptedException e) { + // ignore + } + } + + public UdpSerializedSocketServerTest() { + super(Protocol.UDP, PORT, true); + } + + @Override + protected Layout<? extends Serializable> createLayout() { + return super.createSerializedLayout(); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java new file mode 100644 index 0000000..fa54766 --- /dev/null +++ b/log4j-server/src/test/java/org/apache/logging/log4j/core/net/server/UdpXmlSocketServerTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.net.server; + +import java.io.InputStream; +import java.io.Serializable; +import java.nio.charset.Charset; + +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.net.Protocol; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class UdpXmlSocketServerTest extends AbstractSocketServerTest { + + private static UdpSocketServer<InputStream> server; + + @BeforeClass + public static void setupClass() throws Exception { + (LoggerContext.getContext(false)).reconfigure(); + // Use a tiny buffer just to test the code, the TCP test uses a large buffer + server = new UdpSocketServer<>(PORT_NUM, new XmlInputStreamLogEventBridge(100, + Charset.defaultCharset())); + thread = server.startNewThread(); + } + + @AfterClass + public static void tearDownClass() { + server.shutdown(); + try { + thread.join(); + } catch (final InterruptedException e) { + // ignore + } + } + + public UdpXmlSocketServerTest() { + super(Protocol.UDP, PORT, true); + } + + @Override + protected Layout<? extends Serializable> createLayout() { + return super.createXmlLayout(); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f515fa3c/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index e2ed02f..8f43fa3 100644 --- a/pom.xml +++ b/pom.xml @@ -356,6 +356,11 @@ </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-jul</artifactId> <version>${project.version}</version> </dependency> @@ -1274,6 +1279,7 @@ <module>log4j-web</module> <module>log4j-perf</module> <module>log4j-iostreams</module> + <module>log4j-server</module> <module>log4j-jul</module> <module>log4j-liquibase</module> <module>log4j-api-scala_2.10</module>
