You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2015/08/31 06:37:30 UTC
[09/12] logging-log4j2 git commit: Rename internal JUnit extension
class InitialLoggerContext to LoggerContextRule.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NoConsoleNoAnsiTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NoConsoleNoAnsiTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NoConsoleNoAnsiTest.java
index bdf50d6..394fd70 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NoConsoleNoAnsiTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/NoConsoleNoAnsiTest.java
@@ -20,7 +20,7 @@ import java.util.List;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.util.Constants;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.Before;
import org.junit.Rule;
@@ -37,7 +37,7 @@ public class NoConsoleNoAnsiTest {
+ Constants.LINE_SEPARATOR;
@Rule
- public InitialLoggerContext init = new InitialLoggerContext("log4j2-console-noConsoleNoAnsi.xml");
+ public LoggerContextRule init = new LoggerContextRule("log4j2-console-noConsoleNoAnsi.xml");
private Logger logger;
private ListAppender app;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java
index 94fcfdf..ec526a2 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RegexReplacementTest.java
@@ -20,7 +20,7 @@ import java.util.List;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.util.Constants;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.After;
import org.junit.Before;
@@ -40,7 +40,7 @@ public class RegexReplacementTest {
private static final String EXPECTED = "/RegexReplacementTest" + Constants.LINE_SEPARATOR;
@ClassRule
- public static InitialLoggerContext context = new InitialLoggerContext(CONFIG);
+ public static LoggerContextRule context = new LoggerContextRule(CONFIG);
@Before
public void setUp() throws Exception {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowableTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowableTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowableTest.java
index c0f51e5..9e165a6 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowableTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/RootThrowableTest.java
@@ -19,7 +19,7 @@ package org.apache.logging.log4j.core.pattern;
import java.util.List;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.Before;
import org.junit.ClassRule;
@@ -35,7 +35,7 @@ public class RootThrowableTest {
private static ListAppender app;
@ClassRule
- public static InitialLoggerContext context = new InitialLoggerContext(CONFIG);
+ public static LoggerContextRule context = new LoggerContextRule(CONFIG);
@Before
public void setUp() throws Exception {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java
index 0d6540c..9672367 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/StyleConverterTest.java
@@ -20,7 +20,7 @@ import java.util.List;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.util.Constants;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.Before;
import org.junit.Rule;
@@ -38,7 +38,7 @@ public class StyleConverterTest {
+ Constants.LINE_SEPARATOR;
@Rule
- public InitialLoggerContext init = new InitialLoggerContext("log4j-style.xml");
+ public LoggerContextRule init = new LoggerContextRule("log4j-style.xml");
private Logger logger;
private ListAppender app;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java
index 108564a..80a7ed8 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java
@@ -19,7 +19,7 @@ package org.apache.logging.log4j.core.pattern;
import java.util.List;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.Before;
import org.junit.ClassRule;
@@ -35,7 +35,7 @@ public class ThrowableTest {
private static ListAppender app;
@ClassRule
- public static InitialLoggerContext context = new InitialLoggerContext(CONFIG);
+ public static LoggerContextRule context = new LoggerContextRule(CONFIG);
@Before
public void setUp() throws Exception {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
index ff83c67..505c272 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
@@ -24,7 +24,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.impl.Log4jContextFactory;
import org.apache.logging.log4j.core.selector.ContextSelector;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.status.StatusLogger;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -38,7 +38,7 @@ import static org.junit.Assert.*;
public class ShutdownCallbackRegistryTest {
@Rule
- public final InitialLoggerContext ctx = new InitialLoggerContext("ShutdownCallbackRegistryTest.xml");
+ public final LoggerContextRule ctx = new LoggerContextRule("ShutdownCallbackRegistryTest.xml");
@BeforeClass
public static void setUpClass() throws Exception {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java
deleted file mode 100644
index b1e3ff1..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.junit;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.Configurator;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import static org.junit.Assert.*;
-
-/**
- * JUnit {@link TestRule} for constructing a new LoggerContext using a specified configuration file.
- * If the system property {@code EBUG} is set (e.g., through the command line option {@code -DEBUG}), then the
- * StatusLogger will be set to the debug level. This allows for more debug messages as the StatusLogger will be in the
- * error level until a configuration file has been read and parsed into a tree of Nodes.
- */
-public class InitialLoggerContext implements TestRule {
-
- private final String configLocation;
-
- private LoggerContext context;
-
- private String testClassName;
-
- public InitialLoggerContext(final String configLocation) {
- this.configLocation = configLocation;
- }
-
- @Override
- public Statement apply(final Statement base, final Description description) {
- // Hack: Using -DEBUG as a JVM param sets a property called "EBUG"...
- if (System.getProperties().containsKey("EBUG")) {
- StatusLogger.getLogger().setLevel(Level.DEBUG);
- }
- testClassName = description.getClassName();
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- context = Configurator.initialize(
- description.getDisplayName(),
- description.getTestClass().getClassLoader(),
- configLocation
- );
- try {
- base.evaluate();
- } finally {
- Configurator.shutdown(context);
- StatusLogger.getLogger().reset();
- }
- }
- };
- }
-
- /**
- * Gets the current LoggerContext associated with this rule.
- * @return the current LoggerContext.
- */
- public LoggerContext getContext() {
- return context;
- }
-
- /**
- * Gets a named Logger using the test class's name from this LoggerContext.
- * @return the test class's named Logger.
- */
- public Logger getLogger() {
- return context.getLogger(testClassName);
- }
-
- /**
- * Gets a named Logger in this LoggerContext.
- *
- * @param name the name of the Logger to look up or create.
- * @return the named Logger.
- */
- public Logger getLogger(final String name) {
- return context.getLogger(name);
- }
-
- /**
- * Gets the associated Configuration for the configuration file this was constructed with.
- * @return this LoggerContext's Configuration.
- */
- public Configuration getConfiguration() {
- return context.getConfiguration();
- }
-
- /**
- * Gets a named Appender for this LoggerContext.
- * @param name the name of the Appender to look up.
- * @return the named Appender or {@code null} if it wasn't defined in the configuration.
- */
- public Appender getAppender(final String name) {
- return getConfiguration().getAppenders().get(name);
- }
-
- /**
- * Gets a named Appender or throws an exception for this LoggerContext.
- * @param name the name of the Appender to look up.
- * @return the named Appender.
- * @throws AssertionError if the Appender doesn't exist.
- */
- public Appender getRequiredAppender(final String name) {
- final Appender appender = getAppender(name);
- assertNotNull("Appender named " + name + " was null.", appender);
- return appender;
- }
-
- /**
- * Gets a named ListAppender or throws an exception for this LoggerContext.
- * @param name the name of the ListAppender to look up.
- * @return the named ListAppender.
- * @throws AssertionError if the named ListAppender doesn't exist or isn't a ListAppender.
- */
- public ListAppender getListAppender(final String name) {
- final Appender appender = getAppender(name);
- if (appender instanceof ListAppender) {
- return (ListAppender) appender;
- }
- throw new AssertionError("No ListAppender named " + name + " found.");
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
new file mode 100644
index 0000000..65836d6
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
@@ -0,0 +1,144 @@
+/*
+ * 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.junit;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import static org.junit.Assert.*;
+
+/**
+ * JUnit {@link TestRule} for constructing a new LoggerContext using a specified configuration file.
+ * If the system property {@code EBUG} is set (e.g., through the command line option {@code -DEBUG}), then the
+ * StatusLogger will be set to the debug level. This allows for more debug messages as the StatusLogger will be in the
+ * error level until a configuration file has been read and parsed into a tree of Nodes.
+ */
+public class LoggerContextRule implements TestRule {
+
+ private final String configLocation;
+
+ private LoggerContext context;
+
+ private String testClassName;
+
+ public LoggerContextRule(final String configLocation) {
+ this.configLocation = configLocation;
+ }
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ // Hack: Using -DEBUG as a JVM param sets a property called "EBUG"...
+ if (System.getProperties().containsKey("EBUG")) {
+ StatusLogger.getLogger().setLevel(Level.DEBUG);
+ }
+ testClassName = description.getClassName();
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ context = Configurator.initialize(
+ description.getDisplayName(),
+ description.getTestClass().getClassLoader(),
+ configLocation
+ );
+ try {
+ base.evaluate();
+ } finally {
+ Configurator.shutdown(context);
+ StatusLogger.getLogger().reset();
+ }
+ }
+ };
+ }
+
+ /**
+ * Gets the current LoggerContext associated with this rule.
+ * @return the current LoggerContext.
+ */
+ public LoggerContext getContext() {
+ return context;
+ }
+
+ /**
+ * Gets a named Logger using the test class's name from this LoggerContext.
+ * @return the test class's named Logger.
+ */
+ public Logger getLogger() {
+ return context.getLogger(testClassName);
+ }
+
+ /**
+ * Gets a named Logger in this LoggerContext.
+ *
+ * @param name the name of the Logger to look up or create.
+ * @return the named Logger.
+ */
+ public Logger getLogger(final String name) {
+ return context.getLogger(name);
+ }
+
+ /**
+ * Gets the associated Configuration for the configuration file this was constructed with.
+ * @return this LoggerContext's Configuration.
+ */
+ public Configuration getConfiguration() {
+ return context.getConfiguration();
+ }
+
+ /**
+ * Gets a named Appender for this LoggerContext.
+ * @param name the name of the Appender to look up.
+ * @return the named Appender or {@code null} if it wasn't defined in the configuration.
+ */
+ public Appender getAppender(final String name) {
+ return getConfiguration().getAppenders().get(name);
+ }
+
+ /**
+ * Gets a named Appender or throws an exception for this LoggerContext.
+ * @param name the name of the Appender to look up.
+ * @return the named Appender.
+ * @throws AssertionError if the Appender doesn't exist.
+ */
+ public Appender getRequiredAppender(final String name) {
+ final Appender appender = getAppender(name);
+ assertNotNull("Appender named " + name + " was null.", appender);
+ return appender;
+ }
+
+ /**
+ * Gets a named ListAppender or throws an exception for this LoggerContext.
+ * @param name the name of the ListAppender to look up.
+ * @return the named ListAppender.
+ * @throws AssertionError if the named ListAppender doesn't exist or isn't a ListAppender.
+ */
+ public ListAppender getListAppender(final String name) {
+ final Appender appender = getAppender(name);
+ if (appender instanceof ListAppender) {
+ return (ListAppender) appender;
+ }
+ throw new AssertionError("No ListAppender named " + name + " found.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
index df2d148..05fa157 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
@@ -36,7 +36,7 @@ import org.apache.logging.log4j.core.layout.SerializedLayout;
/**
* This appender is primarily used for testing. Use in a real environment is discouraged as the
* List could eventually grow to cause an OutOfMemoryError.
- * @see org.apache.logging.log4j.junit.InitialLoggerContext#getListAppender(String) ILC.getListAppender
+ * @see org.apache.logging.log4j.junit.LoggerContextRule#getListAppender(String) ILC.getListAppender
*/
@Plugin(name = "List", category = "Core", elementType = "appender", printObject = true)
public class ListAppender extends AbstractAppender {
@@ -178,7 +178,7 @@ public class ListAppender extends AbstractAppender {
*
* @param name the name of the ListAppender
* @return the named ListAppender or {@code null} if it does not exist
- * @see org.apache.logging.log4j.junit.InitialLoggerContext#getListAppender(String)
+ * @see org.apache.logging.log4j.junit.LoggerContextRule#getListAppender(String)
*/
public static ListAppender getListAppender(final String name) {
return ((ListAppender) (LoggerContext.getContext(false)).getConfiguration().getAppender(name));
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractStreamTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractStreamTest.java
index 31fd4b9..05502f5 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractStreamTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractStreamTest.java
@@ -1,59 +1,59 @@
-/*
- * 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.io;
-
-import java.util.List;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.spi.ExtendedLogger;
-import org.junit.Before;
-import org.junit.ClassRule;
-
-import static org.hamcrest.core.StringStartsWith.startsWith;
-import static org.junit.Assert.*;
-
-public abstract class AbstractStreamTest {
-
- protected static ExtendedLogger getExtendedLogger() {
- return ctx.getLogger("UnitTestLogger");
- }
-
- protected final static String NEWLINE = System.getProperty("line.separator");
- protected final static Level LEVEL = Level.ERROR;
- protected final static String FIRST = "first";
-
- protected final static String LAST = "last";
-
- @ClassRule
- public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-unit-test.xml");
-
- protected void assertMessages(final String... messages) {
- final List<String> actualMsgs = ctx.getListAppender("UnitTest").getMessages();
- assertEquals("Unexpected number of results.", messages.length, actualMsgs.size());
- for (int i = 0; i < messages.length; i++) {
- final String start = LEVEL.name() + ' ' + messages[i];
- assertThat(actualMsgs.get(i), startsWith(start));
- }
- }
-
- @Before
- public void clearAppender() {
- ctx.getListAppender("UnitTest").clear();
- }
-}
+/*
+ * 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.io;
+
+import java.util.List;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.spi.ExtendedLogger;
+import org.junit.Before;
+import org.junit.ClassRule;
+
+import static org.hamcrest.core.StringStartsWith.startsWith;
+import static org.junit.Assert.*;
+
+public abstract class AbstractStreamTest {
+
+ protected static ExtendedLogger getExtendedLogger() {
+ return ctx.getLogger("UnitTestLogger");
+ }
+
+ protected final static String NEWLINE = System.getProperty("line.separator");
+ protected final static Level LEVEL = Level.ERROR;
+ protected final static String FIRST = "first";
+
+ protected final static String LAST = "last";
+
+ @ClassRule
+ public static LoggerContextRule ctx = new LoggerContextRule("log4j2-streams-unit-test.xml");
+
+ protected void assertMessages(final String... messages) {
+ final List<String> actualMsgs = ctx.getListAppender("UnitTest").getMessages();
+ assertEquals("Unexpected number of results.", messages.length, actualMsgs.size());
+ for (int i = 0; i < messages.length; i++) {
+ final String start = LEVEL.name() + ' ' + messages[i];
+ assertThat(actualMsgs.get(i), startsWith(start));
+ }
+ }
+
+ @Before
+ public void clearAppender() {
+ ctx.getListAppender("UnitTest").clear();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java
index 6db45b1..d81e173 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java
@@ -1,55 +1,55 @@
-/*
- * 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.io;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Before;
-import org.junit.ClassRule;
-
-import static org.junit.Assert.*;
-
-public class IoBuilderCallerInfoTesting {
-
- protected static Logger getExtendedLogger() {
- return ctx.getLogger("ClassAndMethodLogger");
- }
-
- protected static Logger getLogger() {
- return getExtendedLogger();
- }
-
- protected final static Level LEVEL = Level.WARN;
-
- @ClassRule
- public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-calling-info.xml");
-
- public void assertMessages(final String msg, final int size, final String methodName) {
- final ListAppender appender = ctx.getListAppender("ClassAndMethod");
- assertEquals(msg + ".size", size, appender.getMessages().size());
- for (final String message : appender.getMessages()) {
- assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message);
- }
- }
-
- @Before
- public void clearAppender() {
- ctx.getListAppender("ClassAndMethod").clear();
- }
-}
+/*
+ * 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.io;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Before;
+import org.junit.ClassRule;
+
+import static org.junit.Assert.*;
+
+public class IoBuilderCallerInfoTesting {
+
+ protected static Logger getExtendedLogger() {
+ return ctx.getLogger("ClassAndMethodLogger");
+ }
+
+ protected static Logger getLogger() {
+ return getExtendedLogger();
+ }
+
+ protected final static Level LEVEL = Level.WARN;
+
+ @ClassRule
+ public static LoggerContextRule ctx = new LoggerContextRule("log4j2-streams-calling-info.xml");
+
+ public void assertMessages(final String msg, final int size, final String methodName) {
+ final ListAppender appender = ctx.getListAppender("ClassAndMethod");
+ assertEquals(msg + ".size", size, appender.getMessages().size());
+ for (final String message : appender.getMessages()) {
+ assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message);
+ }
+ }
+
+ @Before
+ public void clearAppender() {
+ ctx.getListAppender("ClassAndMethod").clear();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderTest.java
index cc90e01..9205355 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderTest.java
@@ -1,51 +1,51 @@
-/*
- * 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.io;
-
-import java.io.PrintStream;
-import java.util.List;
-
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.*;
-
-public class IoBuilderTest {
-
- @Rule
- public InitialLoggerContext context = new InitialLoggerContext("log4j2-streams-calling-info.xml");
-
- @Test
- public void testNoArgBuilderCallerClassInfo() throws Exception {
- try (final PrintStream ps = IoBuilder.forLogger().buildPrintStream()) {
- ps.println("discarded");
- final ListAppender app = context.getListAppender("IoBuilderTest");
- final List<String> messages = app.getMessages();
- assertThat(messages, not(empty()));
- assertThat(messages, hasSize(1));
- final String message = messages.get(0);
- assertThat(message, startsWith(getClass().getName() + ".testNoArgBuilderCallerClassInfo"));
- app.clear();
- }
- }
-}
+/*
+ * 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.io;
+
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.*;
+
+public class IoBuilderTest {
+
+ @Rule
+ public LoggerContextRule context = new LoggerContextRule("log4j2-streams-calling-info.xml");
+
+ @Test
+ public void testNoArgBuilderCallerClassInfo() throws Exception {
+ try (final PrintStream ps = IoBuilder.forLogger().buildPrintStream()) {
+ ps.println("discarded");
+ final ListAppender app = context.getListAppender("IoBuilderTest");
+ final List<String> messages = app.getMessages();
+ assertThat(messages, not(empty()));
+ assertThat(messages, hasSize(1));
+ final String message = messages.get(0);
+ assertThat(message, startsWith(getClass().getName() + ".testNoArgBuilderCallerClassInfo"));
+ app.clear();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
index 2be2569..a7c6d0e 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
@@ -1,95 +1,95 @@
-/*
- * 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.io;
-
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.apache.logging.log4j.util.Strings;
-import org.h2.jdbcx.JdbcDataSource;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class LoggerPrintWriterJdbcH2Test {
- @ClassRule
- public static InitialLoggerContext context = new InitialLoggerContext("log4j2-jdbc-driver-manager.xml");
-
- private static final String H2_URL = "jdbc:h2:mem:Log4j";
-
- private static final String PASSWORD = Strings.EMPTY;
-
- private static final String USER_ID = "sa";
-
- private ListAppender listAppender;
-
- private PrintWriter createLoggerPrintWriter() {
- return IoBuilder.forLogger(context.getLogger()).setLevel(Level.ALL).buildPrintWriter();
- }
-
- private ListAppender getListAppender() {
- return listAppender;
- }
-
- protected Connection newConnection() throws SQLException {
- return DriverManager.getConnection(H2_URL, USER_ID, PASSWORD);
- }
-
- private void setListAppender(final ListAppender listAppender) {
- this.listAppender = listAppender;
- }
-
- @Before
- public void setUp() throws Exception {
- this.setListAppender(context.getListAppender("List").clear());
- Assert.assertEquals(0, this.getListAppender().getMessages().size());
- }
-
- @Test
- @Ignore("DataSource#setLogWriter() has no effect in H2, it uses its own internal logging and an SLF4J bridge.")
- public void testDataSource_setLogWriter() throws SQLException {
- final JdbcDataSource dataSource = new JdbcDataSource();
- dataSource.setUrl(H2_URL);
- dataSource.setUser(USER_ID);
- dataSource.setPassword(PASSWORD);
- dataSource.setLogWriter(createLoggerPrintWriter());
- // dataSource.setLogWriter(new PrintWriter(new OutputStreamWriter(System.out)));
- try (final Connection conn = dataSource.getConnection()) {
- conn.prepareCall("select 1");
- }
- Assert.assertTrue(this.getListAppender().getMessages().size() > 0);
- }
-
- @Test
- public void testDriverManager_setLogWriter() throws SQLException {
- DriverManager.setLogWriter(createLoggerPrintWriter());
- // DriverManager.setLogWriter(new PrintWriter(new OutputStreamWriter(System.out)));
- try (final Connection conn = this.newConnection()) {
- conn.rollback();
- } finally {
- DriverManager.setLogWriter(null);
- }
- Assert.assertTrue(this.getListAppender().getMessages().size() > 0);
- }
-}
+/*
+ * 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.io;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.apache.logging.log4j.util.Strings;
+import org.h2.jdbcx.JdbcDataSource;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class LoggerPrintWriterJdbcH2Test {
+ @ClassRule
+ public static LoggerContextRule context = new LoggerContextRule("log4j2-jdbc-driver-manager.xml");
+
+ private static final String H2_URL = "jdbc:h2:mem:Log4j";
+
+ private static final String PASSWORD = Strings.EMPTY;
+
+ private static final String USER_ID = "sa";
+
+ private ListAppender listAppender;
+
+ private PrintWriter createLoggerPrintWriter() {
+ return IoBuilder.forLogger(context.getLogger()).setLevel(Level.ALL).buildPrintWriter();
+ }
+
+ private ListAppender getListAppender() {
+ return listAppender;
+ }
+
+ protected Connection newConnection() throws SQLException {
+ return DriverManager.getConnection(H2_URL, USER_ID, PASSWORD);
+ }
+
+ private void setListAppender(final ListAppender listAppender) {
+ this.listAppender = listAppender;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ this.setListAppender(context.getListAppender("List").clear());
+ Assert.assertEquals(0, this.getListAppender().getMessages().size());
+ }
+
+ @Test
+ @Ignore("DataSource#setLogWriter() has no effect in H2, it uses its own internal logging and an SLF4J bridge.")
+ public void testDataSource_setLogWriter() throws SQLException {
+ final JdbcDataSource dataSource = new JdbcDataSource();
+ dataSource.setUrl(H2_URL);
+ dataSource.setUser(USER_ID);
+ dataSource.setPassword(PASSWORD);
+ dataSource.setLogWriter(createLoggerPrintWriter());
+ // dataSource.setLogWriter(new PrintWriter(new OutputStreamWriter(System.out)));
+ try (final Connection conn = dataSource.getConnection()) {
+ conn.prepareCall("select 1");
+ }
+ Assert.assertTrue(this.getListAppender().getMessages().size() > 0);
+ }
+
+ @Test
+ public void testDriverManager_setLogWriter() throws SQLException {
+ DriverManager.setLogWriter(createLoggerPrintWriter());
+ // DriverManager.setLogWriter(new PrintWriter(new OutputStreamWriter(System.out)));
+ try (final Connection conn = this.newConnection()) {
+ conn.rollback();
+ } finally {
+ DriverManager.setLogWriter(null);
+ }
+ Assert.assertTrue(this.getListAppender().getMessages().size() > 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
----------------------------------------------------------------------
diff --git a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
index 20ca67f..27697b7 100644
--- a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
+++ b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
@@ -1,67 +1,67 @@
-/*
- * 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.jcl;
-
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class CallerInformationTest {
-
- // config from log4j-core test-jar
- private static final String CONFIG = "log4j2-calling-class.xml";
-
- @Rule
- public final InitialLoggerContext ctx = new InitialLoggerContext(CONFIG);
-
- @Test
- public void testClassLogger() throws Exception {
- final ListAppender app = ctx.getListAppender("Class").clear();
- final Log logger = LogFactory.getLog("ClassLogger");
- logger.info("Ignored message contents.");
- logger.warn("Verifying the caller class is still correct.");
- logger.error("Hopefully nobody breaks me!");
- final List<String> messages = app.getMessages();
- assertEquals("Incorrect number of messages.", 3, messages.size());
- for (final String message : messages) {
- assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
- }
- }
-
- @Test
- public void testMethodLogger() throws Exception {
- final ListAppender app = ctx.getListAppender("Method").clear();
- final Log logger = LogFactory.getLog("MethodLogger");
- logger.info("More messages.");
- logger.warn("CATASTROPHE INCOMING!");
- logger.error("ZOMBIES!!!");
- logger.warn("brains~~~");
- logger.info("Itchy. Tasty.");
- final List<String> messages = app.getMessages();
- assertEquals("Incorrect number of messages.", 5, messages.size());
- for (final String message : messages) {
- assertEquals("Incorrect caller method name.", "testMethodLogger", message);
- }
- }
-}
+/*
+ * 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.jcl;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class CallerInformationTest {
+
+ // config from log4j-core test-jar
+ private static final String CONFIG = "log4j2-calling-class.xml";
+
+ @Rule
+ public final LoggerContextRule ctx = new LoggerContextRule(CONFIG);
+
+ @Test
+ public void testClassLogger() throws Exception {
+ final ListAppender app = ctx.getListAppender("Class").clear();
+ final Log logger = LogFactory.getLog("ClassLogger");
+ logger.info("Ignored message contents.");
+ logger.warn("Verifying the caller class is still correct.");
+ logger.error("Hopefully nobody breaks me!");
+ final List<String> messages = app.getMessages();
+ assertEquals("Incorrect number of messages.", 3, messages.size());
+ for (final String message : messages) {
+ assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
+ }
+ }
+
+ @Test
+ public void testMethodLogger() throws Exception {
+ final ListAppender app = ctx.getListAppender("Method").clear();
+ final Log logger = LogFactory.getLog("MethodLogger");
+ logger.info("More messages.");
+ logger.warn("CATASTROPHE INCOMING!");
+ logger.error("ZOMBIES!!!");
+ logger.warn("brains~~~");
+ logger.info("Itchy. Tasty.");
+ final List<String> messages = app.getMessages();
+ assertEquals("Incorrect number of messages.", 5, messages.size());
+ for (final String message : messages) {
+ assertEquals("Incorrect caller method name.", "testMethodLogger", message);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
index 6106b6f..3e73b50 100644
--- a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
+++ b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
@@ -1,65 +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.jcl;
-
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.logging.log4j.core.util.Constants;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasSize;
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class LoggerTest {
-
- private static final String CONFIG = "log4j-test1.xml";
-
- @Rule
- public final InitialLoggerContext context = new InitialLoggerContext(CONFIG);
-
- @Test
- public void testLog() {
- final Log logger = LogFactory.getLog("LoggerTest");
- logger.debug("Test message");
- verify("List", "o.a.l.l.j.LoggerTest Test message MDC{}" + Constants.LINE_SEPARATOR);
- logger.debug("Exception: " , new NullPointerException("Test"));
- verify("List", "o.a.l.l.j.LoggerTest Exception: MDC{}" + Constants.LINE_SEPARATOR);
- logger.info("Info Message");
- verify("List", "o.a.l.l.j.LoggerTest Info Message MDC{}" + Constants.LINE_SEPARATOR);
- logger.info("Info Message {}");
- verify("List", "o.a.l.l.j.LoggerTest Info Message {} MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- private void verify(final String name, final String expected) {
- final ListAppender listApp = context.getListAppender(name);
- final List<String> events = listApp.getMessages();
- assertThat(events, hasSize(1));
- final String actual = events.get(0);
- assertThat(actual, equalTo(expected));
- listApp.clear();
- }
-
-}
+/*
+ * 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.jcl;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class LoggerTest {
+
+ private static final String CONFIG = "log4j-test1.xml";
+
+ @Rule
+ public final LoggerContextRule context = new LoggerContextRule(CONFIG);
+
+ @Test
+ public void testLog() {
+ final Log logger = LogFactory.getLog("LoggerTest");
+ logger.debug("Test message");
+ verify("List", "o.a.l.l.j.LoggerTest Test message MDC{}" + Constants.LINE_SEPARATOR);
+ logger.debug("Exception: " , new NullPointerException("Test"));
+ verify("List", "o.a.l.l.j.LoggerTest Exception: MDC{}" + Constants.LINE_SEPARATOR);
+ logger.info("Info Message");
+ verify("List", "o.a.l.l.j.LoggerTest Info Message MDC{}" + Constants.LINE_SEPARATOR);
+ logger.info("Info Message {}");
+ verify("List", "o.a.l.l.j.LoggerTest Info Message {} MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ private void verify(final String name, final String expected) {
+ final ListAppender listApp = context.getListAppender(name);
+ final List<String> events = listApp.getMessages();
+ assertThat(events, hasSize(1));
+ final String actual = events.get(0);
+ assertThat(actual, equalTo(expected));
+ listApp.clear();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CallerInformationTest.java
----------------------------------------------------------------------
diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CallerInformationTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CallerInformationTest.java
index 04fe136..dedaa4e 100644
--- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CallerInformationTest.java
+++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/CallerInformationTest.java
@@ -1,78 +1,78 @@
-/*
- * 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.jul;
-
-import java.util.List;
-import java.util.logging.Logger;
-
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class CallerInformationTest {
-
- // config from log4j-core test-jar
- private static final String CONFIG = "log4j2-calling-class.xml";
-
- @Rule
- public final InitialLoggerContext ctx = new InitialLoggerContext(CONFIG);
-
- @BeforeClass
- public static void setUpClass() {
- System.setProperty("java.util.logging.manager", LogManager.class.getName());
- }
-
- @AfterClass
- public static void tearDownClass() {
- System.clearProperty("java.util.logging.manager");
- }
-
- @Test
- public void testClassLogger() throws Exception {
- final ListAppender app = ctx.getListAppender("Class").clear();
- final Logger logger = Logger.getLogger("ClassLogger");
- logger.info("Ignored message contents.");
- logger.warning("Verifying the caller class is still correct.");
- logger.severe("Hopefully nobody breaks me!");
- final List<String> messages = app.getMessages();
- assertEquals("Incorrect number of messages.", 3, messages.size());
- for (final String message : messages) {
- assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
- }
- }
-
- @Test
- public void testMethodLogger() throws Exception {
- final ListAppender app = ctx.getListAppender("Method").clear();
- final Logger logger = Logger.getLogger("MethodLogger");
- logger.info("More messages.");
- logger.warning("CATASTROPHE INCOMING!");
- logger.severe("ZOMBIES!!!");
- logger.warning("brains~~~");
- logger.info("Itchy. Tasty.");
- final List<String> messages = app.getMessages();
- assertEquals("Incorrect number of messages.", 5, messages.size());
- for (final String message : messages) {
- assertEquals("Incorrect caller method name.", "testMethodLogger", message);
- }
- }
-}
+/*
+ * 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.jul;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class CallerInformationTest {
+
+ // config from log4j-core test-jar
+ private static final String CONFIG = "log4j2-calling-class.xml";
+
+ @Rule
+ public final LoggerContextRule ctx = new LoggerContextRule(CONFIG);
+
+ @BeforeClass
+ public static void setUpClass() {
+ System.setProperty("java.util.logging.manager", LogManager.class.getName());
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ System.clearProperty("java.util.logging.manager");
+ }
+
+ @Test
+ public void testClassLogger() throws Exception {
+ final ListAppender app = ctx.getListAppender("Class").clear();
+ final Logger logger = Logger.getLogger("ClassLogger");
+ logger.info("Ignored message contents.");
+ logger.warning("Verifying the caller class is still correct.");
+ logger.severe("Hopefully nobody breaks me!");
+ final List<String> messages = app.getMessages();
+ assertEquals("Incorrect number of messages.", 3, messages.size());
+ for (final String message : messages) {
+ assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
+ }
+ }
+
+ @Test
+ public void testMethodLogger() throws Exception {
+ final ListAppender app = ctx.getListAppender("Method").clear();
+ final Logger logger = Logger.getLogger("MethodLogger");
+ logger.info("More messages.");
+ logger.warning("CATASTROPHE INCOMING!");
+ logger.severe("ZOMBIES!!!");
+ logger.warning("brains~~~");
+ logger.info("Itchy. Tasty.");
+ final List<String> messages = app.getMessages();
+ assertEquals("Incorrect number of messages.", 5, messages.size());
+ for (final String message : messages) {
+ assertEquals("Incorrect caller method name.", "testMethodLogger", message);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
----------------------------------------------------------------------
diff --git a/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java b/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
index 2b061c6..2513526 100644
--- a/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
+++ b/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/MongoDbTest.java
@@ -1,37 +1,37 @@
-/*
- * 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.nosql.appender;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-
-@Ignore("Requires a running MongoDB server")
-public class MongoDbTest {
-
- @ClassRule
- public static InitialLoggerContext context = new InitialLoggerContext("log4j2-mongodb.xml");
-
- @Test
- public void test() {
- final Logger logger = LogManager.getLogger();
- logger.info("Hello log");
- }
-}
+/*
+ * 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.nosql.appender;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore("Requires a running MongoDB server")
+public class MongoDbTest {
+
+ @ClassRule
+ public static LoggerContextRule context = new LoggerContextRule("log4j2-mongodb.xml");
+
+ @Test
+ public void test() {
+ final Logger logger = LogManager.getLogger();
+ logger.info("Hello log");
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java
----------------------------------------------------------------------
diff --git a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java
index 255d911..a3e59f0 100644
--- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java
+++ b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java
@@ -1,67 +1,67 @@
-/*
- * 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.slf4j;
-
-import java.util.List;
-
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Rule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.Assert.assertEquals;
-
-public class CallerInformationTest {
-
- // config from log4j-core test-jar
- private static final String CONFIG = "log4j2-calling-class.xml";
-
- @Rule
- public final InitialLoggerContext ctx = new InitialLoggerContext(CONFIG);
-
- @Test
- public void testClassLogger() throws Exception {
- final ListAppender app = ctx.getListAppender("Class").clear();
- final Logger logger = LoggerFactory.getLogger("ClassLogger");
- logger.info("Ignored message contents.");
- logger.warn("Verifying the caller class is still correct.");
- logger.error("Hopefully nobody breaks me!");
- final List<String> messages = app.getMessages();
- assertEquals("Incorrect number of messages.", 3, messages.size());
- for (final String message : messages) {
- assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
- }
- }
-
- @Test
- public void testMethodLogger() throws Exception {
- final ListAppender app = ctx.getListAppender("Method").clear();
- final Logger logger = LoggerFactory.getLogger("MethodLogger");
- logger.info("More messages.");
- logger.warn("CATASTROPHE INCOMING!");
- logger.error("ZOMBIES!!!");
- logger.warn("brains~~~");
- logger.info("Itchy. Tasty.");
- final List<String> messages = app.getMessages();
- assertEquals("Incorrect number of messages.", 5, messages.size());
- for (final String message : messages) {
- assertEquals("Incorrect caller method name.", "testMethodLogger", message);
- }
- }
-}
+/*
+ * 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.slf4j;
+
+import java.util.List;
+
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+
+public class CallerInformationTest {
+
+ // config from log4j-core test-jar
+ private static final String CONFIG = "log4j2-calling-class.xml";
+
+ @Rule
+ public final LoggerContextRule ctx = new LoggerContextRule(CONFIG);
+
+ @Test
+ public void testClassLogger() throws Exception {
+ final ListAppender app = ctx.getListAppender("Class").clear();
+ final Logger logger = LoggerFactory.getLogger("ClassLogger");
+ logger.info("Ignored message contents.");
+ logger.warn("Verifying the caller class is still correct.");
+ logger.error("Hopefully nobody breaks me!");
+ final List<String> messages = app.getMessages();
+ assertEquals("Incorrect number of messages.", 3, messages.size());
+ for (final String message : messages) {
+ assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
+ }
+ }
+
+ @Test
+ public void testMethodLogger() throws Exception {
+ final ListAppender app = ctx.getListAppender("Method").clear();
+ final Logger logger = LoggerFactory.getLogger("MethodLogger");
+ logger.info("More messages.");
+ logger.warn("CATASTROPHE INCOMING!");
+ logger.error("ZOMBIES!!!");
+ logger.warn("brains~~~");
+ logger.info("Itchy. Tasty.");
+ final List<String> messages = app.getMessages();
+ assertEquals("Incorrect number of messages.", 5, messages.size());
+ for (final String message : messages) {
+ assertEquals("Incorrect caller method name.", "testMethodLogger", message);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/546f4d04/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
index 7ed538a..0fa6e65 100644
--- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
+++ b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
@@ -1,182 +1,182 @@
-/*
- * 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.slf4j;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import java.util.Locale;
-
-import org.apache.logging.log4j.core.util.Constants;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-import org.slf4j.Marker;
-import org.slf4j.ext.EventData;
-import org.slf4j.ext.EventLogger;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
-import org.slf4j.spi.LocationAwareLogger;
-
-/**
- *
- */
-public class LoggerTest {
-
- private static final String CONFIG = "log4j-test1.xml";
-
- @ClassRule
- public static InitialLoggerContext ctx = new InitialLoggerContext(CONFIG);
-
- Logger logger = LoggerFactory.getLogger("LoggerTest");
- XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
-
- @Test
- public void basicFlow() {
- xlogger.entry();
- verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Constants.LINE_SEPARATOR);
- xlogger.exit();
- verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- @Test
- public void simpleFlow() {
- xlogger.entry(CONFIG);
- verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Constants.LINE_SEPARATOR);
- xlogger.exit(0);
- verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- @Test
- public void throwing() {
- xlogger.throwing(new IllegalArgumentException("Test Exception"));
- verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- @Test
- public void catching() {
- try {
- throw new NullPointerException();
- } catch (final Exception e) {
- xlogger.catching(e);
- verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Constants.LINE_SEPARATOR);
- }
- }
-
- @Test
- public void debug() {
- logger.debug("Debug message");
- verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- @Test
- public void debugNoParms() {
- logger.debug("Debug message {}");
- verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEPARATOR);
- logger.debug("Debug message {}", (Object[]) null);
- verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEPARATOR);
- ((LocationAwareLogger)logger).log(null, Log4jLogger.class.getName(), LocationAwareLogger.DEBUG_INT,
- "Debug message {}", null, null);
- verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEPARATOR);
- }
-
-
- @Test
- public void debugWithParms() {
- logger.debug("Hello, {}", "World");
- verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- @Test
- public void mdc() {
-
- MDC.put("TestYear", "2010");
- logger.debug("Debug message");
- verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Constants.LINE_SEPARATOR);
- MDC.clear();
- logger.debug("Debug message");
- verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- /**
- * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-793">LOG4J2-793</a>
- */
- @Test
- public void supportsCustomSLF4JMarkers() {
- final Marker marker = new CustomFlatMarker("TEST");
- logger.debug(marker, "Test");
- verify("List", "o.a.l.s.LoggerTest Test MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- @Test
- public void testRootLogger() {
- final Logger l = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- assertNotNull("No Root Logger", l);
- assertEquals(Logger.ROOT_LOGGER_NAME, l.getName());
- }
-
- @Test
- public void doubleSubst() {
- logger.debug("Hello, {}", "Log4j {}");
- verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Constants.LINE_SEPARATOR);
- xlogger.debug("Hello, {}", "Log4j {}");
- verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Constants.LINE_SEPARATOR);
- }
-
- @Test
- public void testEventLogger() {
- MDC.put("loginId", "JohnDoe");
- MDC.put("ipAddress", "192.168.0.120");
- MDC.put("locale", Locale.US.getDisplayName());
- final EventData data = new EventData();
- data.setEventType("Transfer");
- data.setEventId("Audit@18060");
- data.setMessage("Transfer Complete");
- data.put("ToAccount", "123456");
- data.put("FromAccount", "123457");
- data.put("Amount", "200.00");
- EventLogger.logEvent(data);
- MDC.clear();
- verify("EventLogger", "o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete" + Constants.LINE_SEPARATOR);
- }
-
- private void verify(final String name, final String expected) {
- final ListAppender listApp = ctx.getListAppender(name);
- assertNotNull("Missing Appender", listApp);
- final List<String> events = listApp.getMessages();
- assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size()== 1);
- final String actual = events.get(0);
- assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
- listApp.clear();
- }
-
- @Before
- @After
- public void cleanup() {
- MDC.clear();
- ctx.getListAppender("List").clear();
- ctx.getListAppender("EventLogger").clear();
- }
-}
+/*
+ * 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.slf4j;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.ext.EventData;
+import org.slf4j.ext.EventLogger;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+import org.slf4j.spi.LocationAwareLogger;
+
+/**
+ *
+ */
+public class LoggerTest {
+
+ private static final String CONFIG = "log4j-test1.xml";
+
+ @ClassRule
+ public static LoggerContextRule ctx = new LoggerContextRule(CONFIG);
+
+ Logger logger = LoggerFactory.getLogger("LoggerTest");
+ XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
+
+ @Test
+ public void basicFlow() {
+ xlogger.entry();
+ verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Constants.LINE_SEPARATOR);
+ xlogger.exit();
+ verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ @Test
+ public void simpleFlow() {
+ xlogger.entry(CONFIG);
+ verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Constants.LINE_SEPARATOR);
+ xlogger.exit(0);
+ verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ @Test
+ public void throwing() {
+ xlogger.throwing(new IllegalArgumentException("Test Exception"));
+ verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ @Test
+ public void catching() {
+ try {
+ throw new NullPointerException();
+ } catch (final Exception e) {
+ xlogger.catching(e);
+ verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Constants.LINE_SEPARATOR);
+ }
+ }
+
+ @Test
+ public void debug() {
+ logger.debug("Debug message");
+ verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ @Test
+ public void debugNoParms() {
+ logger.debug("Debug message {}");
+ verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEPARATOR);
+ logger.debug("Debug message {}", (Object[]) null);
+ verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEPARATOR);
+ ((LocationAwareLogger)logger).log(null, Log4jLogger.class.getName(), LocationAwareLogger.DEBUG_INT,
+ "Debug message {}", null, null);
+ verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+
+ @Test
+ public void debugWithParms() {
+ logger.debug("Hello, {}", "World");
+ verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ @Test
+ public void mdc() {
+
+ MDC.put("TestYear", "2010");
+ logger.debug("Debug message");
+ verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Constants.LINE_SEPARATOR);
+ MDC.clear();
+ logger.debug("Debug message");
+ verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ /**
+ * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-793">LOG4J2-793</a>
+ */
+ @Test
+ public void supportsCustomSLF4JMarkers() {
+ final Marker marker = new CustomFlatMarker("TEST");
+ logger.debug(marker, "Test");
+ verify("List", "o.a.l.s.LoggerTest Test MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ @Test
+ public void testRootLogger() {
+ final Logger l = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ assertNotNull("No Root Logger", l);
+ assertEquals(Logger.ROOT_LOGGER_NAME, l.getName());
+ }
+
+ @Test
+ public void doubleSubst() {
+ logger.debug("Hello, {}", "Log4j {}");
+ verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Constants.LINE_SEPARATOR);
+ xlogger.debug("Hello, {}", "Log4j {}");
+ verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Constants.LINE_SEPARATOR);
+ }
+
+ @Test
+ public void testEventLogger() {
+ MDC.put("loginId", "JohnDoe");
+ MDC.put("ipAddress", "192.168.0.120");
+ MDC.put("locale", Locale.US.getDisplayName());
+ final EventData data = new EventData();
+ data.setEventType("Transfer");
+ data.setEventId("Audit@18060");
+ data.setMessage("Transfer Complete");
+ data.put("ToAccount", "123456");
+ data.put("FromAccount", "123457");
+ data.put("Amount", "200.00");
+ EventLogger.logEvent(data);
+ MDC.clear();
+ verify("EventLogger", "o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete" + Constants.LINE_SEPARATOR);
+ }
+
+ private void verify(final String name, final String expected) {
+ final ListAppender listApp = ctx.getListAppender(name);
+ assertNotNull("Missing Appender", listApp);
+ final List<String> events = listApp.getMessages();
+ assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size()== 1);
+ final String actual = events.get(0);
+ assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
+ listApp.clear();
+ }
+
+ @Before
+ @After
+ public void cleanup() {
+ MDC.clear();
+ ctx.getListAppender("List").clear();
+ ctx.getListAppender("EventLogger").clear();
+ }
+}