Repository: logging-log4j2 Updated Branches: refs/heads/master 804fbe4f5 -> fc918475c
Remove unused imports Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fc918475 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fc918475 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fc918475 Branch: refs/heads/master Commit: fc918475cf2b2fd120b4f832ec473396a51afc21 Parents: 804fbe4 Author: ggregory <[email protected]> Authored: Wed Mar 2 01:20:35 2016 -0800 Committer: ggregory <[email protected]> Committed: Wed Mar 2 01:20:35 2016 -0800 ---------------------------------------------------------------------- .../logging/log4j/AbstractLoggerTest.java | 2 - .../org/apache/logging/log4j/LoggerTest.java | 1107 +++++++++--------- .../apache/logging/log4j/core/jmx/Server.java | 1 - .../core/pattern/MessagePatternConverter.java | 1 - .../appender/rolling/PatternProcessorTest.java | 1 - .../async/perftest/CountingNoOpAppender.java | 4 - .../log4j/core/util/CronExpressionTest.java | 1 - .../log4j/core/util/WatchManagerTest.java | 2 - .../log4j/jmx/gui/ClientGuiJConsolePlugin.java | 2 - .../logging/log4j/perf/nogc/AbstractLogger.java | 1 - .../logging/log4j/perf/nogc/DemoAppender.java | 1 - .../perf/nogc/NoGcMessagePatternConverter.java | 3 - .../CustomConfigurationFactory.java | 2 - .../org/apache/logging/slf4j/Log4j1222Test.java | 1 - 14 files changed, 553 insertions(+), 576 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java index 399b450..ac77b97 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java @@ -20,14 +20,12 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.message.ObjectMessage; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.apache.logging.log4j.message.SimpleMessage; import org.apache.logging.log4j.spi.AbstractLogger; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java index 323d8fb..3fe3b61 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java @@ -1,554 +1,553 @@ -/* - * 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; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import org.apache.logging.log4j.message.EntryMessage; -import org.apache.logging.log4j.message.JsonMessage; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.message.ObjectMessage; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; -import org.apache.logging.log4j.message.SimpleMessageFactory; -import org.apache.logging.log4j.message.StringFormatterMessageFactory; -import org.apache.logging.log4j.message.StructuredDataMessage; -import org.apache.logging.log4j.util.MessageSupplier; -import org.apache.logging.log4j.util.Strings; -import org.apache.logging.log4j.util.Supplier; -import org.junit.Before; -import org.junit.Test; -/** - * - */ -public class LoggerTest { - - private static class TestParameterizedMessageFactory { - // empty - } - - private static class TestStringFormatterMessageFactory { - // empty - } - - private final TestLogger logger = (TestLogger) LogManager.getLogger("LoggerTest"); - private final List<String> results = logger.getEntries(); - - @Test - public void basicFlow() { - logger.entry(); - logger.exit(); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), equalTo("ENTER[ FLOW ] TRACE Enter")); - assertThat("incorrect Exit", results.get(1), equalTo("EXIT[ FLOW ] TRACE Exit")); - - } - - @Test - public void flowTracingMessage() { - logger.traceEntry(new JsonMessage(System.getProperties())); - final Response response = new Response(-1, "Generic error"); - logger.traceExit(new JsonMessage(response), response); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Missing entry data", results.get(0), containsString("\"java.runtime.name\":")); - assertThat("incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - assertThat("Missing exit data", results.get(1), containsString("\"message\":\"Generic error\"")); - } - - @Test - public void flowTracingString_ObjectArray1() { - logger.traceEntry("doFoo(a={}, b={})", 1, 2); - logger.traceExit("doFoo(a=1, b=2): {}", 3); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); - } - - @Test - public void flowTracingExitValueOnly() { - logger.traceEntry("doFoo(a={}, b={})", 1, 2); - logger.traceExit(3); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - assertThat("Missing exit data", results.get(1), containsString("3")); - } - - @Test - public void flowTracingString_ObjectArray2() { - EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", 1, 2); - logger.traceExit(msg, 3); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); - } - - @Test - public void flowTracingVoidReturn() { - EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", 1, 2); - logger.traceExit(msg); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - assertThat("Missing exit data", results.get(1), endsWith("doFoo(a=1, b=2)")); - } - - @Test - public void flowTracingNoExitArgs() { - logger.traceEntry(); - logger.traceExit(); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - } - - @Test - public void flowTracingNoArgs() { - final EntryMessage message = logger.traceEntry(); - logger.traceExit(message); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - } - - @Test - public void flowTracingString_SupplierOfObjectMessages() { - EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<Message>() { - @Override - public Message get() { - return new ObjectMessage(1); - } - }, new Supplier<Message>() { - @Override - public Message get() { - return new ObjectMessage(2); - } - }); - logger.traceExit(msg, 3); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); - } - - @Test - public void flowTracingString_SupplierOfStrings() { - EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<String>() { - @Override - public String get() { - return "1"; - } - }, new Supplier<String>() { - @Override - public String get() { - return "2"; - } - }); - logger.traceExit(msg, 3); - assertEquals(2, results.size()); - assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); - assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); - assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); - assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); - } - - @Test - public void catching() { - try { - throw new NullPointerException(); - } catch (final Exception e) { - logger.catching(e); - assertEquals(1, results.size()); - assertThat("Incorrect Catching", - results.get(0), startsWith("CATCHING[ EXCEPTION ] ERROR Catching java.lang.NullPointerException")); - } - } - - @Test - public void debug() { - logger.debug("Debug message"); - assertEquals(1, results.size()); - assertTrue("Incorrect message", results.get(0).startsWith(" DEBUG Debug message")); - } - - @Test - public void debugObject() { - logger.debug(new Date()); - assertEquals(1, results.size()); - assertTrue("Invalid length", results.get(0).length() > 7); - } - - @Test - public void debugWithParms() { - logger.debug("Hello, {}", "World"); - assertEquals(1, results.size()); - assertTrue("Incorrect substitution", results.get(0).startsWith(" DEBUG Hello, World")); - } - - @Test - public void debugWithParmsAndThrowable() { - logger.debug("Hello, {}", "World", new RuntimeException("Test Exception")); - assertEquals(1, results.size()); - assertTrue("Unexpected results: " + results.get(0), - results.get(0).startsWith(" DEBUG Hello, World java.lang.RuntimeException: Test Exception")); - } - - @Test - public void getFormatterLogger() { - // The TestLogger logger was already created in an instance variable for this class. - // The message factory is only used when the logger is created. - final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(); - final TestLogger altLogger = (TestLogger) LogManager.getFormatterLogger(getClass()); - assertEquals(testLogger.getName(), altLogger.getName()); - assertNotNull(testLogger); - assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); - assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getFormatterLogger_Class() { - // The TestLogger logger was already created in an instance variable for this class. - // The message factory is only used when the logger is created. - final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class); - assertNotNull(testLogger); - assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); - assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getFormatterLogger_Object() { - // The TestLogger logger was already created in an instance variable for this class. - // The message factory is only used when the logger is created. - final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory()); - assertNotNull(testLogger); - assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); - assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getFormatterLogger_String() { - final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory"); - assertNotNull(testLogger); - assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); - assertEquals(messageFactory, testLogger.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_Class_ParameterizedMessageFactory() { - // The TestLogger logger was already created in an instance variable for this class. - // The message factory is only used when the logger is created. - final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestParameterizedMessageFactory.class, - messageFactory); - assertNotNull(testLogger); - assertEquals(messageFactory, testLogger.getMessageFactory()); - testLogger.debug("{}", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_Class_StringFormatterMessageFactory() { - // The TestLogger logger was already created in an instance variable for this class. - // The message factory is only used when the logger is created. - final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestStringFormatterMessageFactory.class, - StringFormatterMessageFactory.INSTANCE); - assertNotNull(testLogger); - assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_Object_ParameterizedMessageFactory() { - // The TestLogger logger was already created in an instance variable for this class. - // The message factory is only used when the logger is created. - final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestParameterizedMessageFactory(), - messageFactory); - assertNotNull(testLogger); - assertEquals(messageFactory, testLogger.getMessageFactory()); - testLogger.debug("{}", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_Object_StringFormatterMessageFactory() { - // The TestLogger logger was already created in an instance variable for this class. - // The message factory is only used when the logger is created. - final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestStringFormatterMessageFactory(), - messageFactory); - assertNotNull(testLogger); - assertEquals(messageFactory, testLogger.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_String_MessageFactoryMismatch() { - final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch", - messageFactory); - assertNotNull(testLogger); - assertEquals(messageFactory, testLogger.getMessageFactory()); - final TestLogger testLogger2 = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch", - ParameterizedMessageFactory.INSTANCE); - assertNotNull(testLogger2); - //TODO: How to test? - //This test context always creates new loggers, other test context impls I tried fail other tests. - //assertEquals(messageFactory, testLogger2.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_String_ParameterizedMessageFactory() { - final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_ParameterizedMessageFactory", - messageFactory); - assertNotNull(testLogger); - assertEquals(messageFactory, testLogger.getMessageFactory()); - testLogger.debug("{}", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_String_SimpleMessageFactory() { - final SimpleMessageFactory messageFactory = SimpleMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", - messageFactory); - assertNotNull(testLogger); - assertEquals(messageFactory, testLogger.getMessageFactory()); - testLogger.debug("{} %,d {foo}", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(" DEBUG {} %,d {foo}", testLogger.getEntries().get(0)); - } - - @Test - public void getLogger_String_StringFormatterMessageFactory() { - final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; - final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", - messageFactory); - assertNotNull(testLogger); - assertEquals(messageFactory, testLogger.getMessageFactory()); - testLogger.debug("%,d", Integer.MAX_VALUE); - assertEquals(1, testLogger.getEntries().size()); - assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); - } - - @Test - public void getLoggerByClass() { - final Logger classLogger = LogManager.getLogger(LoggerTest.class); - assertNotNull(classLogger); - } - - @Test - public void getLoggerByNullClass() { - // Returns a SimpleLogger - assertNotNull(LogManager.getLogger((Class<?>) null)); - } - - @Test - public void getLoggerByNullObject() { - // Returns a SimpleLogger - assertNotNull(LogManager.getLogger((Object) null)); - } - - @Test - public void getLoggerByNullString() { - // Returns a SimpleLogger - assertNotNull(LogManager.getLogger((String) null)); - } - - @Test - public void getLoggerByObject() { - final Logger classLogger = LogManager.getLogger(this); - assertNotNull(classLogger); - assertEquals(classLogger, LogManager.getLogger(LoggerTest.class)); - } - - @Test - public void getRootLogger() { - assertNotNull(LogManager.getRootLogger()); - assertNotNull(LogManager.getLogger(Strings.EMPTY)); - assertNotNull(LogManager.getLogger(LogManager.ROOT_LOGGER_NAME)); - assertEquals(LogManager.getRootLogger(), LogManager.getLogger(Strings.EMPTY)); - assertEquals(LogManager.getRootLogger(), LogManager.getLogger(LogManager.ROOT_LOGGER_NAME)); - } - - @Test - public void isAllEnabled() { - assertTrue("Incorrect level", logger.isEnabled(Level.ALL)); - } - - @Test - public void isDebugEnabled() { - assertTrue("Incorrect level", logger.isDebugEnabled()); - assertTrue("Incorrect level", logger.isEnabled(Level.DEBUG)); - } - - @Test - public void isErrorEnabled() { - assertTrue("Incorrect level", logger.isErrorEnabled()); - assertTrue("Incorrect level", logger.isEnabled(Level.ERROR)); - } - - @Test - public void isFatalEnabled() { - assertTrue("Incorrect level", logger.isFatalEnabled()); - assertTrue("Incorrect level", logger.isEnabled(Level.FATAL)); - } - - @Test - public void isInfoEnabled() { - assertTrue("Incorrect level", logger.isInfoEnabled()); - assertTrue("Incorrect level", logger.isEnabled(Level.INFO)); - } - - @Test - public void isOffEnabled() { - assertTrue("Incorrect level", logger.isEnabled(Level.OFF)); - } - - @Test - public void isTraceEnabled() { - assertTrue("Incorrect level", logger.isTraceEnabled()); - assertTrue("Incorrect level", logger.isEnabled(Level.TRACE)); - } - - @Test - public void isWarnEnabled() { - assertTrue("Incorrect level", logger.isWarnEnabled()); - assertTrue("Incorrect level", logger.isEnabled(Level.WARN)); - } - - @Test - public void mdc() { - - ThreadContext.put("TestYear", Integer.valueOf(2010).toString()); - logger.debug("Debug message"); - ThreadContext.clearMap(); - logger.debug("Debug message"); - assertEquals(2, results.size()); - assertTrue("Incorrect MDC: " + results.get(0), - results.get(0).startsWith(" DEBUG Debug message {TestYear=2010}")); - assertTrue("MDC not cleared?: " + results.get(1), - results.get(1).startsWith(" DEBUG Debug message")); - } - - @Test - public void printf() { - logger.printf(Level.DEBUG, "Debug message %d", 1); - logger.printf(Level.DEBUG, MarkerManager.getMarker("Test"), "Debug message %d", 2); - assertEquals(2, results.size()); - assertThat("Incorrect message", results.get(0), startsWith(" DEBUG Debug message 1")); - assertThat("Incorrect message", results.get(1), startsWith("Test DEBUG Debug message 2")); - } - - @Before - public void setup() { - results.clear(); - } - - @Test - public void structuredData() { - ThreadContext.put("loginId", "JohnDoe"); - ThreadContext.put("ipAddress", "192.168.0.120"); - ThreadContext.put("locale", Locale.US.getDisplayName()); - final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer"); - msg.put("ToAccount", "123456"); - msg.put("FromAccount", "123457"); - msg.put("Amount", "200.00"); - logger.info(MarkerManager.getMarker("EVENT"), msg); - ThreadContext.clearMap(); - assertEquals(1, results.size()); - assertThat("Incorrect structured data: ", results.get(0), startsWith( - "EVENT INFO Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete")); - } - - @Test - public void throwing() { - logger.throwing(new IllegalArgumentException("Test Exception")); - assertEquals(1, results.size()); - assertThat("Incorrect Throwing", - results.get(0), startsWith("THROWING[ EXCEPTION ] ERROR Throwing java.lang.IllegalArgumentException: Test Exception")); - } - - - private class Response { - int status; - String message; - - public Response(int status, String message) { - this.status = status; - this.message = message; - } - - public int getStatus() { - return status; - } - - public void setStatus(int status) { - this.status = status; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = 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; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.endsWith; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import org.apache.logging.log4j.message.EntryMessage; +import org.apache.logging.log4j.message.JsonMessage; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.ObjectMessage; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; +import org.apache.logging.log4j.message.SimpleMessageFactory; +import org.apache.logging.log4j.message.StringFormatterMessageFactory; +import org.apache.logging.log4j.message.StructuredDataMessage; +import org.apache.logging.log4j.util.Strings; +import org.apache.logging.log4j.util.Supplier; +import org.junit.Before; +import org.junit.Test; +/** + * + */ +public class LoggerTest { + + private static class TestParameterizedMessageFactory { + // empty + } + + private static class TestStringFormatterMessageFactory { + // empty + } + + private final TestLogger logger = (TestLogger) LogManager.getLogger("LoggerTest"); + private final List<String> results = logger.getEntries(); + + @Test + public void basicFlow() { + logger.entry(); + logger.exit(); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), equalTo("ENTER[ FLOW ] TRACE Enter")); + assertThat("incorrect Exit", results.get(1), equalTo("EXIT[ FLOW ] TRACE Exit")); + + } + + @Test + public void flowTracingMessage() { + logger.traceEntry(new JsonMessage(System.getProperties())); + final Response response = new Response(-1, "Generic error"); + logger.traceExit(new JsonMessage(response), response); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Missing entry data", results.get(0), containsString("\"java.runtime.name\":")); + assertThat("incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + assertThat("Missing exit data", results.get(1), containsString("\"message\":\"Generic error\"")); + } + + @Test + public void flowTracingString_ObjectArray1() { + logger.traceEntry("doFoo(a={}, b={})", 1, 2); + logger.traceExit("doFoo(a=1, b=2): {}", 3); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); + } + + @Test + public void flowTracingExitValueOnly() { + logger.traceEntry("doFoo(a={}, b={})", 1, 2); + logger.traceExit(3); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + assertThat("Missing exit data", results.get(1), containsString("3")); + } + + @Test + public void flowTracingString_ObjectArray2() { + EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", 1, 2); + logger.traceExit(msg, 3); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); + } + + @Test + public void flowTracingVoidReturn() { + EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", 1, 2); + logger.traceExit(msg); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + assertThat("Missing exit data", results.get(1), endsWith("doFoo(a=1, b=2)")); + } + + @Test + public void flowTracingNoExitArgs() { + logger.traceEntry(); + logger.traceExit(); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + } + + @Test + public void flowTracingNoArgs() { + final EntryMessage message = logger.traceEntry(); + logger.traceExit(message); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + } + + @Test + public void flowTracingString_SupplierOfObjectMessages() { + EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<Message>() { + @Override + public Message get() { + return new ObjectMessage(1); + } + }, new Supplier<Message>() { + @Override + public Message get() { + return new ObjectMessage(2); + } + }); + logger.traceExit(msg, 3); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); + } + + @Test + public void flowTracingString_SupplierOfStrings() { + EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<String>() { + @Override + public String get() { + return "1"; + } + }, new Supplier<String>() { + @Override + public String get() { + return "2"; + } + }); + logger.traceExit(msg, 3); + assertEquals(2, results.size()); + assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); + assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)")); + assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit")); + assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3")); + } + + @Test + public void catching() { + try { + throw new NullPointerException(); + } catch (final Exception e) { + logger.catching(e); + assertEquals(1, results.size()); + assertThat("Incorrect Catching", + results.get(0), startsWith("CATCHING[ EXCEPTION ] ERROR Catching java.lang.NullPointerException")); + } + } + + @Test + public void debug() { + logger.debug("Debug message"); + assertEquals(1, results.size()); + assertTrue("Incorrect message", results.get(0).startsWith(" DEBUG Debug message")); + } + + @Test + public void debugObject() { + logger.debug(new Date()); + assertEquals(1, results.size()); + assertTrue("Invalid length", results.get(0).length() > 7); + } + + @Test + public void debugWithParms() { + logger.debug("Hello, {}", "World"); + assertEquals(1, results.size()); + assertTrue("Incorrect substitution", results.get(0).startsWith(" DEBUG Hello, World")); + } + + @Test + public void debugWithParmsAndThrowable() { + logger.debug("Hello, {}", "World", new RuntimeException("Test Exception")); + assertEquals(1, results.size()); + assertTrue("Unexpected results: " + results.get(0), + results.get(0).startsWith(" DEBUG Hello, World java.lang.RuntimeException: Test Exception")); + } + + @Test + public void getFormatterLogger() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(); + final TestLogger altLogger = (TestLogger) LogManager.getFormatterLogger(getClass()); + assertEquals(testLogger.getName(), altLogger.getName()); + assertNotNull(testLogger); + assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); + assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getFormatterLogger_Class() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class); + assertNotNull(testLogger); + assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); + assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getFormatterLogger_Object() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory()); + assertNotNull(testLogger); + assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); + assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getFormatterLogger_String() { + final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory"); + assertNotNull(testLogger); + assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_Class_ParameterizedMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestParameterizedMessageFactory.class, + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("{}", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_Class_StringFormatterMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestStringFormatterMessageFactory.class, + StringFormatterMessageFactory.INSTANCE); + assertNotNull(testLogger); + assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_Object_ParameterizedMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestParameterizedMessageFactory(), + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("{}", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_Object_StringFormatterMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestStringFormatterMessageFactory(), + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_String_MessageFactoryMismatch() { + final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch", + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + final TestLogger testLogger2 = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch", + ParameterizedMessageFactory.INSTANCE); + assertNotNull(testLogger2); + //TODO: How to test? + //This test context always creates new loggers, other test context impls I tried fail other tests. + //assertEquals(messageFactory, testLogger2.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_String_ParameterizedMessageFactory() { + final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_ParameterizedMessageFactory", + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("{}", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_String_SimpleMessageFactory() { + final SimpleMessageFactory messageFactory = SimpleMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("{} %,d {foo}", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(" DEBUG {} %,d {foo}", testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_String_StringFormatterMessageFactory() { + final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; + final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLoggerByClass() { + final Logger classLogger = LogManager.getLogger(LoggerTest.class); + assertNotNull(classLogger); + } + + @Test + public void getLoggerByNullClass() { + // Returns a SimpleLogger + assertNotNull(LogManager.getLogger((Class<?>) null)); + } + + @Test + public void getLoggerByNullObject() { + // Returns a SimpleLogger + assertNotNull(LogManager.getLogger((Object) null)); + } + + @Test + public void getLoggerByNullString() { + // Returns a SimpleLogger + assertNotNull(LogManager.getLogger((String) null)); + } + + @Test + public void getLoggerByObject() { + final Logger classLogger = LogManager.getLogger(this); + assertNotNull(classLogger); + assertEquals(classLogger, LogManager.getLogger(LoggerTest.class)); + } + + @Test + public void getRootLogger() { + assertNotNull(LogManager.getRootLogger()); + assertNotNull(LogManager.getLogger(Strings.EMPTY)); + assertNotNull(LogManager.getLogger(LogManager.ROOT_LOGGER_NAME)); + assertEquals(LogManager.getRootLogger(), LogManager.getLogger(Strings.EMPTY)); + assertEquals(LogManager.getRootLogger(), LogManager.getLogger(LogManager.ROOT_LOGGER_NAME)); + } + + @Test + public void isAllEnabled() { + assertTrue("Incorrect level", logger.isEnabled(Level.ALL)); + } + + @Test + public void isDebugEnabled() { + assertTrue("Incorrect level", logger.isDebugEnabled()); + assertTrue("Incorrect level", logger.isEnabled(Level.DEBUG)); + } + + @Test + public void isErrorEnabled() { + assertTrue("Incorrect level", logger.isErrorEnabled()); + assertTrue("Incorrect level", logger.isEnabled(Level.ERROR)); + } + + @Test + public void isFatalEnabled() { + assertTrue("Incorrect level", logger.isFatalEnabled()); + assertTrue("Incorrect level", logger.isEnabled(Level.FATAL)); + } + + @Test + public void isInfoEnabled() { + assertTrue("Incorrect level", logger.isInfoEnabled()); + assertTrue("Incorrect level", logger.isEnabled(Level.INFO)); + } + + @Test + public void isOffEnabled() { + assertTrue("Incorrect level", logger.isEnabled(Level.OFF)); + } + + @Test + public void isTraceEnabled() { + assertTrue("Incorrect level", logger.isTraceEnabled()); + assertTrue("Incorrect level", logger.isEnabled(Level.TRACE)); + } + + @Test + public void isWarnEnabled() { + assertTrue("Incorrect level", logger.isWarnEnabled()); + assertTrue("Incorrect level", logger.isEnabled(Level.WARN)); + } + + @Test + public void mdc() { + + ThreadContext.put("TestYear", Integer.valueOf(2010).toString()); + logger.debug("Debug message"); + ThreadContext.clearMap(); + logger.debug("Debug message"); + assertEquals(2, results.size()); + assertTrue("Incorrect MDC: " + results.get(0), + results.get(0).startsWith(" DEBUG Debug message {TestYear=2010}")); + assertTrue("MDC not cleared?: " + results.get(1), + results.get(1).startsWith(" DEBUG Debug message")); + } + + @Test + public void printf() { + logger.printf(Level.DEBUG, "Debug message %d", 1); + logger.printf(Level.DEBUG, MarkerManager.getMarker("Test"), "Debug message %d", 2); + assertEquals(2, results.size()); + assertThat("Incorrect message", results.get(0), startsWith(" DEBUG Debug message 1")); + assertThat("Incorrect message", results.get(1), startsWith("Test DEBUG Debug message 2")); + } + + @Before + public void setup() { + results.clear(); + } + + @Test + public void structuredData() { + ThreadContext.put("loginId", "JohnDoe"); + ThreadContext.put("ipAddress", "192.168.0.120"); + ThreadContext.put("locale", Locale.US.getDisplayName()); + final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer"); + msg.put("ToAccount", "123456"); + msg.put("FromAccount", "123457"); + msg.put("Amount", "200.00"); + logger.info(MarkerManager.getMarker("EVENT"), msg); + ThreadContext.clearMap(); + assertEquals(1, results.size()); + assertThat("Incorrect structured data: ", results.get(0), startsWith( + "EVENT INFO Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete")); + } + + @Test + public void throwing() { + logger.throwing(new IllegalArgumentException("Test Exception")); + assertEquals(1, results.size()); + assertThat("Incorrect Throwing", + results.get(0), startsWith("THROWING[ EXCEPTION ] ERROR Throwing java.lang.IllegalArgumentException: Test Exception")); + } + + + private class Response { + int status; + String message; + + public Response(int status, String message) { + this.status = status; + this.message = message; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java index dc01507..cafbb41 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java @@ -41,7 +41,6 @@ import org.apache.logging.log4j.core.config.LoggerConfig; import org.apache.logging.log4j.core.impl.Log4jContextFactory; import org.apache.logging.log4j.core.selector.ContextSelector; import org.apache.logging.log4j.core.util.Constants; -import org.apache.logging.log4j.core.util.Loader; import org.apache.logging.log4j.spi.LoggerContextFactory; import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.PropertiesUtil; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java index fd389f4..4565e21 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java @@ -21,7 +21,6 @@ import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.MultiformatMessage; -import org.apache.logging.log4j.message.ReusableMessage; import org.apache.logging.log4j.util.StringBuilderFormattable; /** http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java index 3b9e22a..556268d 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessorTest.java @@ -22,7 +22,6 @@ import java.util.Calendar; import java.util.Date; import java.util.Locale; -import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.*; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/CountingNoOpAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/CountingNoOpAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/CountingNoOpAppender.java index 6140fb6..bb92bcf 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/CountingNoOpAppender.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/CountingNoOpAppender.java @@ -16,18 +16,14 @@ */ package org.apache.logging.log4j.core.async.perftest; -import java.io.Serializable; import java.util.Objects; -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.appender.AbstractAppender; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.core.layout.PatternLayout; /** * No-Operation Appender that counts events. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java index 2e73d9c..d76ef4e 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java @@ -18,7 +18,6 @@ package org.apache.logging.log4j.core.util; import org.junit.Test; -import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchManagerTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchManagerTest.java index 9e229fd..4108f26 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchManagerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchManagerTest.java @@ -27,8 +27,6 @@ import java.nio.file.StandardCopyOption; import java.util.Queue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.core.config.ConfigurationScheduler; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-jmx-gui/src/main/java/org/apache/logging/log4j/jmx/gui/ClientGuiJConsolePlugin.java ---------------------------------------------------------------------- diff --git a/log4j-jmx-gui/src/main/java/org/apache/logging/log4j/jmx/gui/ClientGuiJConsolePlugin.java b/log4j-jmx-gui/src/main/java/org/apache/logging/log4j/jmx/gui/ClientGuiJConsolePlugin.java index 538dc8d..f7405c2 100644 --- a/log4j-jmx-gui/src/main/java/org/apache/logging/log4j/jmx/gui/ClientGuiJConsolePlugin.java +++ b/log4j-jmx-gui/src/main/java/org/apache/logging/log4j/jmx/gui/ClientGuiJConsolePlugin.java @@ -22,8 +22,6 @@ import java.util.Map; import javax.swing.JPanel; import javax.swing.SwingWorker; -import com.sun.tools.jconsole.JConsolePlugin; - /** * Adapts the {@code ClientGui} to the {@code JConsolePlugin} API. */ http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/AbstractLogger.java ---------------------------------------------------------------------- diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/AbstractLogger.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/AbstractLogger.java index 3ac215d..471e30c 100644 --- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/AbstractLogger.java +++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/AbstractLogger.java @@ -16,7 +16,6 @@ */ package org.apache.logging.log4j.perf.nogc; -import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.message.Message; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/DemoAppender.java ---------------------------------------------------------------------- diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/DemoAppender.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/DemoAppender.java index 7fa3d76..fd05ac3 100644 --- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/DemoAppender.java +++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/DemoAppender.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.layout.ByteBufferDestination; -import org.apache.logging.log4j.core.layout.Encoder; /** * Demo Appender that does not do any I/O. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcMessagePatternConverter.java ---------------------------------------------------------------------- diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcMessagePatternConverter.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcMessagePatternConverter.java index 0ff39fd..4ecec89 100644 --- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcMessagePatternConverter.java +++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcMessagePatternConverter.java @@ -18,10 +18,7 @@ package org.apache.logging.log4j.perf.nogc; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.pattern.ConverterKeys; import org.apache.logging.log4j.core.pattern.LogEventPatternConverter; -import org.apache.logging.log4j.core.pattern.PatternConverter; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.MultiformatMessage; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java b/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java index 3c59b34..7ef0d92 100644 --- a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java +++ b/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java @@ -21,8 +21,6 @@ import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationSource; import org.apache.logging.log4j.core.config.Order; import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.xml.XmlConfiguration; - import java.net.URI; /** http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc918475/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java index 019660e..1e17161 100644 --- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java +++ b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java @@ -17,7 +17,6 @@ package org.apache.logging.slf4j; -import org.apache.logging.log4j.TestLogger; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
