You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/07/21 21:08:42 UTC
[46/50] [abbrv] logging-log4j2 git commit: [LOG4J2-1472] Make
org.apache.logging.log4j.core.LoggerContext implement Closeable.
[LOG4J2-1472] Make org.apache.logging.log4j.core.LoggerContext implement
Closeable.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/afc7ccbd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/afc7ccbd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/afc7ccbd
Branch: refs/heads/AutoCloseableLock
Commit: afc7ccbd38eb30db24f9566092bf64674b10fb5f
Parents: 8d16c04
Author: Gary Gregory <gg...@apache.org>
Authored: Wed Jul 20 20:21:22 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Wed Jul 20 20:21:22 2016 -0700
----------------------------------------------------------------------
.../logging/log4j/core/LoggerContext.java | 10 +-
.../log4j/FormatterLoggerManualExample.java | 7 +-
.../apache/logging/log4j/LogRolloverTest.java | 18 ++-
.../ConsoleAppenderAnsiMessagesMain.java | 110 +++++++------
.../ConsoleAppenderAnsiStyleJira180Main.java | 119 +++++++-------
.../ConsoleAppenderAnsiStyleJira272Main.java | 121 +++++++-------
.../ConsoleAppenderAnsiStyleJira319Main.java | 123 +++++++-------
.../ConsoleAppenderAnsiStyleLayoutMain.java | 149 +++++++++--------
.../ConsoleAppenderAnsiStyleNameLayoutMain.java | 11 +-
...nsoleAppenderDefaultSuppressedThrowable.java | 131 ++++++++-------
...nsoleAppenderHighlightLayoutDefaultMain.java | 11 +-
...nsoleAppenderHighlightLayoutLogbackMain.java | 11 +-
.../ConsoleAppenderHighlightLayoutMain.java | 11 +-
.../ConsoleAppenderJAnsiMessageMain.java | 160 +++++++++----------
.../ConsoleAppenderNoAnsiStyleLayoutMain.java | 145 ++++++++---------
.../log4j/core/appender/Jira739Test.java | 103 ++++++------
.../core/appender/ProgressConsoleTest.java | 7 +-
.../log4j/core/config/ConfiguratorTest.java | 5 +-
.../core/config/TestConfiguratorError.java | 13 +-
.../builder/ConfigurationAssemblerTest.java | 5 +-
.../core/filter/DynamicThresholdFilterTest.java | 26 +--
.../lookup/MainInputArgumentsLookupTest.java | 11 +-
src/changes/changes.xml | 3 +
23 files changed, 641 insertions(+), 669 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index 1cad582..6d8c578 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.io.Closeable;
import java.io.File;
import java.net.URI;
import java.util.Collection;
@@ -54,8 +55,8 @@ import static org.apache.logging.log4j.core.util.ShutdownCallbackRegistry.*;
* applications and a reference to the Configuration. The Configuration will contain the configured loggers, appenders,
* filters, etc and will be atomically updated whenever a reconfigure occurs.
*/
-public class LoggerContext extends AbstractLifeCycle implements org.apache.logging.log4j.spi.LoggerContext, Terminable,
- ConfigurationListener {
+public class LoggerContext extends AbstractLifeCycle
+ implements org.apache.logging.log4j.spi.LoggerContext, Closeable, Terminable, ConfigurationListener {
/**
* Property name of the property change event fired if the configuration is changed.
@@ -282,6 +283,11 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
}
@Override
+ public void close() {
+ stop();
+ }
+
+ @Override
public void terminate() {
stop();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java b/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java
index 3ade1eb..d5a1438 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java
@@ -40,16 +40,13 @@ public class FormatterLoggerManualExample {
* @param args
*/
public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(FormatterLoggerManualExample.class.getName(),
- "target/test-classes/log4j2-console.xml");
- try {
+ try (final LoggerContext ctx = Configurator.initialize(FormatterLoggerManualExample.class.getName(),
+ "target/test-classes/log4j2-console.xml");) {
final User user = new User();
logger.debug("User %s with birthday %s", user.getName(), user.getBirthdayCalendar());
logger.debug("User %1$s with birthday %2$tm %2$te, %2$tY", user.getName(), user.getBirthdayCalendar());
logger.debug("Integer.MAX_VALUE = %,d", Integer.MAX_VALUE);
logger.debug("Long.MAX_VALUE = %,d", Long.MAX_VALUE);
- } finally {
- Configurator.shutdown(ctx);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
index 045a182..f1739dd 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
@@ -16,10 +16,11 @@
*/
package org.apache.logging.log4j;
-import org.apache.logging.log4j.core.config.Configurator;
-
import java.io.File;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
/**
*
*/
@@ -27,15 +28,16 @@ public class LogRolloverTest {
private static final String CONFIG = "src/test/resources/rollover-test.xml";
-
public static void main(final String[] args) throws Exception {
final File file = new File(CONFIG);
- Configurator.initialize("LogTest", LogRolloverTest.class.getClassLoader(), file.toURI());
- final Logger logger = LogManager.getLogger("TestLogger");
+ try (final LoggerContext ctx = Configurator.initialize("LogTest", LogRolloverTest.class.getClassLoader(),
+ file.toURI())) {
+ final Logger logger = LogManager.getLogger("TestLogger");
- for (long i=0; ; i+=1) {
- logger.debug("Sequence: " + i);
- Thread.sleep(250);
+ for (long i = 0;; i += 1) {
+ logger.debug("Sequence: " + i);
+ Thread.sleep(250);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java
index d963737..2569ed3 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java
@@ -1,56 +1,54 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender;
-
-import java.io.IOException;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-
-/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest of the log entry
- * (time stamp for example) is in the default color for that console.
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiMessagesMain log4j-core/target/test-classes/log4j2-console.xml
- * </pre>
- */
-public class ConsoleAppenderAnsiMessagesMain {
-
- private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiMessagesMain.class);
-
- public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
- "target/test-classes/log4j2-console.xml");
- try {
- LOG.fatal("\u001b[1;35mFatal message.\u001b[0m");
- LOG.error("\u001b[1;31mError message.\u001b[0m");
- LOG.warn("\u001b[0;33mWarning message.\u001b[0m");
- LOG.info("\u001b[0;32mInformation message.\u001b[0m");
- LOG.debug("\u001b[0;36mDebug message.\u001b[0m");
- LOG.trace("\u001b[0;30mTrace message.\u001b[0m");
- LOG.error("\u001b[1;31mError message.\u001b[0m", new IOException("test"));
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+/**
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiMessagesMain log4j-core/target/test-classes/log4j2-console.xml
+ * </pre>
+ */
+public class ConsoleAppenderAnsiMessagesMain {
+
+ private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiMessagesMain.class);
+
+ public static void main(final String[] args) {
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ "target/test-classes/log4j2-console.xml")) {
+ LOG.fatal("\u001b[1;35mFatal message.\u001b[0m");
+ LOG.error("\u001b[1;31mError message.\u001b[0m");
+ LOG.warn("\u001b[0;33mWarning message.\u001b[0m");
+ LOG.info("\u001b[0;32mInformation message.\u001b[0m");
+ LOG.debug("\u001b[0;36mDebug message.\u001b[0m");
+ LOG.trace("\u001b[0;30mTrace message.\u001b[0m");
+ LOG.error("\u001b[1;31mError message.\u001b[0m", new IOException("test"));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira180Main.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira180Main.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira180Main.java
index b0e1e9d..cc01bd7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira180Main.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira180Main.java
@@ -1,60 +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.core.appender;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-
-/**
- * Tests https://issues.apache.org/jira/browse/LOG4J2-180
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleJira180Main log4j-core/target/test-classes/log4j2-180.xml
- * </pre>
- */
-public class ConsoleAppenderAnsiStyleJira180Main {
-
- private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleJira180Main.class);
-
- public static void main(final String[] args) {
- // System.out.println(System.getProperty("java.class.path"));
- final String config = args.length == 0 ? "target/test-classes/log4j2-180.xml" : args[0];
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
- try {
- LOG.fatal("Fatal message.");
- LOG.error("Error message.");
- LOG.warn("Warning message.");
- LOG.info("Information message.");
- LOG.debug("Debug message.");
- LOG.trace("Trace message.");
- try {
- throw new NullPointerException();
- } catch (final Exception e) {
- LOG.error("Error message.", e);
- LOG.catching(Level.ERROR, e);
- }
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+/**
+ * Tests https://issues.apache.org/jira/browse/LOG4J2-180
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleJira180Main log4j-core/target/test-classes/log4j2-180.xml
+ * </pre>
+ */
+public class ConsoleAppenderAnsiStyleJira180Main {
+
+ private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleJira180Main.class);
+
+ public static void main(final String[] args) {
+ // System.out.println(System.getProperty("java.class.path"));
+ final String config = args.length == 0 ? "target/test-classes/log4j2-180.xml" : args[0];
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ config)) {
+ LOG.fatal("Fatal message.");
+ LOG.error("Error message.");
+ LOG.warn("Warning message.");
+ LOG.info("Information message.");
+ LOG.debug("Debug message.");
+ LOG.trace("Trace message.");
+ try {
+ throw new NullPointerException();
+ } catch (final Exception e) {
+ LOG.error("Error message.", e);
+ LOG.catching(Level.ERROR, e);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira272Main.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira272Main.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira272Main.java
index c5d8b81..ac4bf1c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira272Main.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira272Main.java
@@ -1,62 +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.core.appender;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-
-/**
- * Tests https://issues.apache.org/jira/browse/LOG4J2-272
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleJira272Main log4j-core/target/test-classes/log4j2-272.xml
- * </pre>
- */
-public class ConsoleAppenderAnsiStyleJira272Main {
-
- private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleJira272Main.class);
-
- public static void main(final String[] args) {
- // System.out.println(System.getProperty("java.class.path"));
- final String config = args.length == 0 ? "target/test-classes/log4j2-272.xml" : args[0];
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
- try {
- LOG.fatal("Fatal message.");
- LOG.error("Error message.");
- LOG.warn("Warning message.");
- LOG.info("Information message.");
- LOG.debug("Debug message.");
- LOG.trace("Trace message.");
- try {
- throw new NullPointerException();
- } catch (final Exception e) {
- LOG.error("Error message.", e);
- LOG.catching(Level.ERROR, e);
- }
- LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
- LOG.info("Information message.");
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+/**
+ * Tests https://issues.apache.org/jira/browse/LOG4J2-272
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleJira272Main log4j-core/target/test-classes/log4j2-272.xml
+ * </pre>
+ */
+public class ConsoleAppenderAnsiStyleJira272Main {
+
+ private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleJira272Main.class);
+
+ public static void main(final String[] args) {
+ // System.out.println(System.getProperty("java.class.path"));
+ final String config = args.length == 0 ? "target/test-classes/log4j2-272.xml" : args[0];
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config)) {
+ LOG.fatal("Fatal message.");
+ LOG.error("Error message.");
+ LOG.warn("Warning message.");
+ LOG.info("Information message.");
+ LOG.debug("Debug message.");
+ LOG.trace("Trace message.");
+ try {
+ throw new NullPointerException();
+ } catch (final Exception e) {
+ LOG.error("Error message.", e);
+ LOG.catching(Level.ERROR, e);
+ }
+ LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
+ LOG.info("Information message.");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
index 29cef2e..edfbb2a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
@@ -1,62 +1,61 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-
-/**
- * Tests https://issues.apache.org/jira/browse/LOG4J2-319
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleJira319Main log4j-core/target/test-classes/log4j2-319.xml
- * </pre>
- */
-public class ConsoleAppenderAnsiStyleJira319Main {
-
- private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleJira319Main.class);
-
- public static void main(final String[] args) {
- // System.out.println(System.getProperty("java.class.path"));
- final String config = args.length == 0 ? "target/test-classes/log4j2-319.xml" : args[0];
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
- try {
- LOG.fatal("Fatal message.");
- LOG.error("Error message.");
- LOG.warn("Warning message.");
- LOG.info("Information message.");
- LOG.debug("Debug message.");
- LOG.trace("Trace message.");
- try {
- throw new NullPointerException();
- } catch (final Exception e) {
- LOG.error("Error message.", e);
- LOG.catching(Level.ERROR, e);
- }
- LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
- LOG.info("Information message.");
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+/**
+ * Tests https://issues.apache.org/jira/browse/LOG4J2-319
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleJira319Main log4j-core/target/test-classes/log4j2-319.xml
+ * </pre>
+ */
+public class ConsoleAppenderAnsiStyleJira319Main {
+
+ private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleJira319Main.class);
+
+ public static void main(final String[] args) {
+ // System.out.println(System.getProperty("java.class.path"));
+ final String config = args.length == 0 ? "target/test-classes/log4j2-319.xml" : args[0];
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ config)) {
+ LOG.fatal("Fatal message.");
+ LOG.error("Error message.");
+ LOG.warn("Warning message.");
+ LOG.info("Information message.");
+ LOG.debug("Debug message.");
+ LOG.trace("Trace message.");
+ try {
+ throw new NullPointerException();
+ } catch (final Exception e) {
+ LOG.error("Error message.", e);
+ LOG.catching(Level.ERROR, e);
+ }
+ LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
+ LOG.info("Information message.");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java
index 7159f53..a91aa3b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java
@@ -1,76 +1,73 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender;
-
-import java.io.IOException;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-import org.junit.Test;
-
-/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
- * of the log entry (time stamp for example) is in the default color for that console.
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- *
- * <pre>
- * mvn -Dtest=org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleLayoutMain test
- * </pre>
- * or:
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleLayoutMain log4j-core/target/test-classes/log4j2-console-style-ansi.xml
- * </pre>
- *
- */
-public class ConsoleAppenderAnsiStyleLayoutMain {
-
- public static void main(final String[] args) {
- new ConsoleAppenderAnsiStyleLayoutMain().test(args);
- }
-
- /**
- * This is a @Test method to make it easy to run from a command line with {@code mvn -Dtest=FQCN test}
- */
- @Test
- public void test() {
- test(null);
- }
-
- public void test(final String[] args) {
- // System.out.println(System.getProperty("java.class.path"));
- final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-style-ansi.xml"
- : args[0];
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
- final Logger logger = LogManager.getLogger(ConsoleAppenderAnsiStyleLayoutMain.class);
- try {
- logger.fatal("Fatal message.");
- logger.error("Error message.");
- logger.warn("Warning message.");
- logger.info("Information message.");
- logger.debug("Debug message.");
- logger.trace("Trace message.");
- logger.error("Error message.", new IOException("test"));
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.junit.Test;
+
+/**
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * mvn -Dtest=org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleLayoutMain test
+ * </pre>
+ * or:
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiStyleLayoutMain log4j-core/target/test-classes/log4j2-console-style-ansi.xml
+ * </pre>
+ *
+ */
+public class ConsoleAppenderAnsiStyleLayoutMain {
+
+ public static void main(final String[] args) {
+ new ConsoleAppenderAnsiStyleLayoutMain().test(args);
+ }
+
+ /**
+ * This is a @Test method to make it easy to run from a command line with {@code mvn -Dtest=FQCN test}
+ */
+ @Test
+ public void test() {
+ test(null);
+ }
+
+ public void test(final String[] args) {
+ // System.out.println(System.getProperty("java.class.path"));
+ final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-style-ansi.xml"
+ : args[0];
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config)) {
+ final Logger logger = LogManager.getLogger(ConsoleAppenderAnsiStyleLayoutMain.class);
+ logger.fatal("Fatal message.");
+ logger.error("Error message.");
+ logger.warn("Warning message.");
+ logger.info("Information message.");
+ logger.debug("Debug message.");
+ logger.trace("Trace message.");
+ logger.error("Error message.", new IOException("test"));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java
index afae402..4a2b26a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java
@@ -24,17 +24,16 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest of the log entry
- * (time stamp for example) is in the default color for that console.
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
*/
public class ConsoleAppenderAnsiStyleNameLayoutMain {
private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleNameLayoutMain.class);
public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
- "target/test-classes/log4j2-console-style-name-ansi.xml");
- try {
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ "target/test-classes/log4j2-console-style-name-ansi.xml")) {
LOG.fatal("Fatal message.");
LOG.error("Error message.");
LOG.warn("Warning message.");
@@ -42,8 +41,6 @@ public class ConsoleAppenderAnsiStyleNameLayoutMain {
LOG.debug("Debug message.");
LOG.trace("Trace message.");
LOG.error("Error message.", new IOException("test"));
- } finally {
- Configurator.shutdown(ctx);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderDefaultSuppressedThrowable.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderDefaultSuppressedThrowable.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderDefaultSuppressedThrowable.java
index e2b6718..756c433 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderDefaultSuppressedThrowable.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderDefaultSuppressedThrowable.java
@@ -1,67 +1,64 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender;
-
-import java.io.IOException;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-
-/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed
- * to the console in color, but the rest of the log entry (time stamp for
- * example) is in the default color for that console.
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- *
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderNoAnsiStyleLayoutMain log4j-core/target/test-classes/log4j2-console-style-ansi.xml
- * </pre>
- */
-public class ConsoleAppenderDefaultSuppressedThrowable {
-
- private static final Logger LOG = LogManager.getLogger(ConsoleAppenderDefaultSuppressedThrowable.class);
-
- public static void main(final String[] args) {
- final String config = args.length == 0 ? "target/test-classes/log4j2-console-default-suppressed-throwable.xml"
- : args[0];
- test(args, config);
- }
-
- static void test(final String[] args, final String config) {
- // System.out.println(System.getProperty("java.class.path"));
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderDefaultSuppressedThrowable.class.getName(),
- config);
- try {
- final IOException ioEx = new IOException("test suppressed");
- ioEx.addSuppressed(new IOException("test suppressed 1", new IOException("test 1")));
- final IOException ioEx2 = new IOException("test 2");
- ioEx2.addSuppressed(new IOException("test 3"));
- ioEx.addSuppressed(new IOException("test suppressed 2", ioEx2));
- final IOException e = new IOException("test", ioEx);
- LOG.error("Error message {}, suppressed?", "Hi", e);
- System.out.println("printStackTrace");
- e.printStackTrace();
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+/**
+ * Shows how to use ANSI escape codes to color messages. Each message is printed
+ * to the console in color, but the rest of the log entry (time stamp for
+ * example) is in the default color for that console.
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderNoAnsiStyleLayoutMain log4j-core/target/test-classes/log4j2-console-style-ansi.xml
+ * </pre>
+ */
+public class ConsoleAppenderDefaultSuppressedThrowable {
+
+ private static final Logger LOG = LogManager.getLogger(ConsoleAppenderDefaultSuppressedThrowable.class);
+
+ public static void main(final String[] args) {
+ final String config = args.length == 0 ? "target/test-classes/log4j2-console-default-suppressed-throwable.xml"
+ : args[0];
+ test(args, config);
+ }
+
+ static void test(final String[] args, final String config) {
+ // System.out.println(System.getProperty("java.class.path"));
+ try (final LoggerContext ctx = Configurator
+ .initialize(ConsoleAppenderDefaultSuppressedThrowable.class.getName(), config)) {
+ final IOException ioEx = new IOException("test suppressed");
+ ioEx.addSuppressed(new IOException("test suppressed 1", new IOException("test 1")));
+ final IOException ioEx2 = new IOException("test 2");
+ ioEx2.addSuppressed(new IOException("test 3"));
+ ioEx.addSuppressed(new IOException("test suppressed 2", ioEx2));
+ final IOException e = new IOException("test", ioEx);
+ LOG.error("Error message {}, suppressed?", "Hi", e);
+ System.out.println("printStackTrace");
+ e.printStackTrace();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutDefaultMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutDefaultMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutDefaultMain.java
index 17943cc..4c3339d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutDefaultMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutDefaultMain.java
@@ -24,17 +24,16 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest of the log entry
- * (time stamp for example) is in the default color for that console.
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
*/
public class ConsoleAppenderHighlightLayoutDefaultMain {
private static final Logger LOG = LogManager.getLogger(ConsoleAppenderHighlightLayoutDefaultMain.class);
public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
- "target/test-classes/log4j2-console-highlight-default.xml");
- try {
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ "target/test-classes/log4j2-console-highlight-default.xml")) {
LOG.fatal("Fatal message.");
LOG.error("Error message.");
LOG.warn("Warning message.");
@@ -42,8 +41,6 @@ public class ConsoleAppenderHighlightLayoutDefaultMain {
LOG.debug("Debug message.");
LOG.trace("Trace message.");
LOG.error("Error message.", new IOException("test"));
- } finally {
- Configurator.shutdown(ctx);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutLogbackMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutLogbackMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutLogbackMain.java
index 14f1b73..89d0f44 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutLogbackMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutLogbackMain.java
@@ -24,17 +24,16 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest of the log entry
- * (time stamp for example) is in the default color for that console.
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
*/
public class ConsoleAppenderHighlightLayoutLogbackMain {
private static final Logger LOG = LogManager.getLogger(ConsoleAppenderHighlightLayoutLogbackMain.class);
public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
- "target/test-classes/log4j2-console-highlight-logback.xml");
- try {
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ "target/test-classes/log4j2-console-highlight-logback.xml")) {
LOG.fatal("Fatal message.");
LOG.error("Error message.");
LOG.warn("Warning message.");
@@ -42,8 +41,6 @@ public class ConsoleAppenderHighlightLayoutLogbackMain {
LOG.debug("Debug message.");
LOG.trace("Trace message.");
LOG.error("Error message.", new IOException("test"));
- } finally {
- Configurator.shutdown(ctx);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutMain.java
index d3ac66e..0ca7e8d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderHighlightLayoutMain.java
@@ -24,17 +24,16 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest of the log entry
- * (time stamp for example) is in the default color for that console.
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
*/
public class ConsoleAppenderHighlightLayoutMain {
private static final Logger LOG = LogManager.getLogger(ConsoleAppenderHighlightLayoutMain.class);
public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
- "target/test-classes/log4j2-console-highlight.xml");
- try {
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ "target/test-classes/log4j2-console-highlight.xml")) {
LOG.fatal("Fatal message.");
LOG.error("Error message.");
LOG.warn("Warning message.");
@@ -42,8 +41,6 @@ public class ConsoleAppenderHighlightLayoutMain {
LOG.debug("Debug message.");
LOG.trace("Trace message.");
LOG.error("Error message.", new IOException("test"));
- } finally {
- Configurator.shutdown(ctx);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderJAnsiMessageMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderJAnsiMessageMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderJAnsiMessageMain.java
index ca5611c..df5ef6a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderJAnsiMessageMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderJAnsiMessageMain.java
@@ -1,81 +1,79 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender;
-
-import static org.fusesource.jansi.Ansi.ansi;
-import static org.fusesource.jansi.Ansi.Color.CYAN;
-import static org.fusesource.jansi.Ansi.Color.RED;
-
-import java.util.Map.Entry;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-import org.junit.Test;
-
-/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
- * of the log entry (time stamp for example) is in the default color for that console.
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- *
- * <pre>
- * mvn -Dtest=org.apache.logging.log4j.core.appender.ConsoleAppenderJAnsiMessageMain test
- * </pre>
- *
- * or, on Windows:
- *
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%USERPROFILE%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderJAnsiMessageMain log4j-core/src/test/resources/log4j2-console-msg-ansi.xml
- * </pre>
- *
- */
-public class ConsoleAppenderJAnsiMessageMain {
-
- public static void main(final String[] args) {
- new ConsoleAppenderJAnsiMessageMain().test(args);
- }
-
- /**
- * This is a @Test method to make it easy to run from a command line with {@code mvn -Dtest=FQCN test}
- */
- @Test
- public void test() {
- test(null);
- }
-
- public void test(final String[] args) {
- // System.out.println(System.getProperty("java.class.path"));
- final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-msg-ansi.xml"
- : args[0];
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
- final Logger logger = LogManager.getLogger(ConsoleAppenderJAnsiMessageMain.class);
- try {
- logger.info(ansi().fg(RED).a("Hello").fg(CYAN).a(" World").reset());
- // JAnsi format:
- // logger.info("@|red Hello|@ @|cyan World|@");
- for (Entry<Object, Object> entry : System.getProperties().entrySet()) {
- logger.info("@|KeyStyle {}|@ = @|ValueStyle {}|@", entry.getKey(), entry.getValue());
- }
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import static org.fusesource.jansi.Ansi.ansi;
+import static org.fusesource.jansi.Ansi.Color.CYAN;
+import static org.fusesource.jansi.Ansi.Color.RED;
+
+import java.util.Map.Entry;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.junit.Test;
+
+/**
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * mvn -Dtest=org.apache.logging.log4j.core.appender.ConsoleAppenderJAnsiMessageMain test
+ * </pre>
+ *
+ * or, on Windows:
+ *
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%USERPROFILE%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderJAnsiMessageMain log4j-core/src/test/resources/log4j2-console-msg-ansi.xml
+ * </pre>
+ *
+ */
+public class ConsoleAppenderJAnsiMessageMain {
+
+ public static void main(final String[] args) {
+ new ConsoleAppenderJAnsiMessageMain().test(args);
+ }
+
+ /**
+ * This is a @Test method to make it easy to run from a command line with {@code mvn -Dtest=FQCN test}
+ */
+ @Test
+ public void test() {
+ test(null);
+ }
+
+ public void test(final String[] args) {
+ // System.out.println(System.getProperty("java.class.path"));
+ final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-msg-ansi.xml"
+ : args[0];
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
+ config)) {
+ final Logger logger = LogManager.getLogger(ConsoleAppenderJAnsiMessageMain.class);
+ logger.info(ansi().fg(RED).a("Hello").fg(CYAN).a(" World").reset());
+ // JAnsi format:
+ // logger.info("@|red Hello|@ @|cyan World|@");
+ for (Entry<Object, Object> entry : System.getProperties().entrySet()) {
+ logger.info("@|KeyStyle {}|@ = @|ValueStyle {}|@", entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java
index 3ce83b4..a7bca96 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java
@@ -1,74 +1,71 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender;
-
-import java.io.IOException;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-
-/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed
- * to the console in color, but the rest of the log entry (time stamp for
- * example) is in the default color for that console.
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- *
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderNoAnsiStyleLayoutMain log4j-core/target/test-classes/log4j2-console-style-ansi.xml
- * </pre>
- */
-public class ConsoleAppenderNoAnsiStyleLayoutMain {
-
- private static final Logger LOG = LogManager.getLogger(ConsoleAppenderNoAnsiStyleLayoutMain.class);
-
- private static void logThrowableFromMethod() {
- LOG.error("Error message.", new IOException("test"));
- }
-
- public static void main(final String[] args) {
- final String config = args.length == 0 ? "target/test-classes/log4j2-console-style-no-ansi.xml" : args[0];
- test(args, config);
- }
-
- static void test(final String[] args, final String config) {
- // System.out.println(System.getProperty("java.class.path"));
- final LoggerContext ctx = Configurator.initialize(ConsoleAppenderNoAnsiStyleLayoutMain.class.getName(), config);
- try {
- LOG.fatal("Fatal message.");
- LOG.error("Error message.");
- LOG.warn("Warning message.");
- LOG.info("Information message.");
- LOG.debug("Debug message.");
- LOG.trace("Trace message.");
- logThrowableFromMethod();
- // This will log the stack trace as well:
- final IOException ioException = new IOException("test");
- LOG.error("Error message {}", "Hi", ioException);
- final Throwable t = new IOException("test suppressed");
- t.addSuppressed(new IOException("test suppressed 2", ioException));
- LOG.error("Error message {}, suppressed?", "Hi", t);
- LOG.error("Error message {}, suppressed?", "Hi", new IOException("test", t));
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+/**
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderNoAnsiStyleLayoutMain log4j-core/target/test-classes/log4j2-console-style-ansi.xml
+ * </pre>
+ */
+public class ConsoleAppenderNoAnsiStyleLayoutMain {
+
+ private static final Logger LOG = LogManager.getLogger(ConsoleAppenderNoAnsiStyleLayoutMain.class);
+
+ private static void logThrowableFromMethod() {
+ LOG.error("Error message.", new IOException("test"));
+ }
+
+ public static void main(final String[] args) {
+ final String config = args.length == 0 ? "target/test-classes/log4j2-console-style-no-ansi.xml" : args[0];
+ test(args, config);
+ }
+
+ static void test(final String[] args, final String config) {
+ // System.out.println(System.getProperty("java.class.path"));
+ try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderNoAnsiStyleLayoutMain.class.getName(),
+ config)) {
+ LOG.fatal("Fatal message.");
+ LOG.error("Error message.");
+ LOG.warn("Warning message.");
+ LOG.info("Information message.");
+ LOG.debug("Debug message.");
+ LOG.trace("Trace message.");
+ logThrowableFromMethod();
+ // This will log the stack trace as well:
+ final IOException ioException = new IOException("test");
+ LOG.error("Error message {}", "Hi", ioException);
+ final Throwable t = new IOException("test suppressed");
+ t.addSuppressed(new IOException("test suppressed 2", ioException));
+ LOG.error("Error message {}, suppressed?", "Hi", t);
+ LOG.error("Error message {}, suppressed?", "Hi", new IOException("test", t));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/Jira739Test.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/Jira739Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/Jira739Test.java
index d0dcff2..e18aaa6 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/Jira739Test.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/Jira739Test.java
@@ -1,53 +1,50 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-
-/**
- * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
- * of the log entry (time stamp for example) is in the default color for that console.
- * <p>
- * Running from a Windows command line from the root of the project:
- * </p>
- *
- * <pre>
- * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiMessagesMain log4j-core/target/test-classes/log4j2-console.xml
- * </pre>
- */
-public class Jira739Test {
-
- private static final Logger LOG = LogManager.getLogger(Jira739Test.class);
-
- public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(Jira739Test.class.getName(),
- "target/test-classes/LOG4J2-739.xml");
- try {
- for (int i = 0; i < 10; i++) {
- LOG.trace("Entering Log4j Example " + i + " times");
- LOG.error("Ohh!Failed!");
- LOG.trace("Exiting Log4j Example." + i + " times");
- }
- } finally {
- Configurator.shutdown(ctx);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+/**
+ * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest
+ * of the log entry (time stamp for example) is in the default color for that console.
+ * <p>
+ * Running from a Windows command line from the root of the project:
+ * </p>
+ *
+ * <pre>
+ * java -classpath log4j-core\target\test-classes;log4j-core\target\classes;log4j-api\target\classes;%HOME%\.m2\repository\org\fusesource\jansi\jansi\1.13\jansi-1.13.jar; org.apache.logging.log4j.core.appender.ConsoleAppenderAnsiMessagesMain log4j-core/target/test-classes/log4j2-console.xml
+ * </pre>
+ */
+public class Jira739Test {
+
+ private static final Logger LOG = LogManager.getLogger(Jira739Test.class);
+
+ public static void main(final String[] args) {
+ try (final LoggerContext ctx = Configurator.initialize(Jira739Test.class.getName(),
+ "target/test-classes/LOG4J2-739.xml")) {
+ for (int i = 0; i < 10; i++) {
+ LOG.trace("Entering Log4j Example " + i + " times");
+ LOG.error("Ohh!Failed!");
+ LOG.trace("Exiting Log4j Example." + i + " times");
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ProgressConsoleTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ProgressConsoleTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ProgressConsoleTest.java
index 3eea975..4e2209f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ProgressConsoleTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ProgressConsoleTest.java
@@ -39,11 +39,10 @@ public class ProgressConsoleTest {
private static final Logger LOG = LogManager.getLogger(ProgressConsoleTest.class);
public static void main(final String[] args) {
- final LoggerContext ctx = Configurator.initialize(ProgressConsoleTest.class.getName(),
- "target/test-classes/log4j2-progress-console.xml");
// src/test/resources/log4j2-console-progress.xml
// target/test-classes/log4j2-progress-console.xml
- try {
+ try (final LoggerContext ctx = Configurator.initialize(ProgressConsoleTest.class.getName(),
+ "target/test-classes/log4j2-progress-console.xml")) {
for (double i = 0; i <= 1; i = i + 0.05) {
updateProgress(i);
try {
@@ -53,8 +52,6 @@ public class ProgressConsoleTest {
e.printStackTrace();
}
}
- } finally {
- Configurator.shutdown(ctx);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java
index 420ec2b..8a40d22 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java
@@ -37,11 +37,8 @@ public class ConfiguratorTest {
}
private void testInitializeFromFilePath(final String path) {
- final LoggerContext loggerContext = Configurator.initialize(getClass().getName(), null, path);
- try {
+ try (final LoggerContext loggerContext = Configurator.initialize(getClass().getName(), null, path)) {
Assert.assertNotNull(loggerContext.getConfiguration().getAppender("List"));
- } finally {
- loggerContext.stop();
}
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java
index 3a9a054..5699f42 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java
@@ -28,7 +28,7 @@ import static org.junit.Assert.*;
*/
public class TestConfiguratorError {
- private static final String FACTORY_PROPERTY_NAME = "log4j2.loggerContextFactory";
+ private static final String FACTORY_PROPERTY_NAME = "log4j2.loggerContextFactory";
@BeforeClass
public static void beforeClass() {
@@ -37,13 +37,16 @@ public class TestConfiguratorError {
@Test
public void testErrorNoClassLoader() throws Exception {
- final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-config.xml");
- assertNull("No LoggerContext should have been returned", ctx);
+ try (final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-config.xml")) {
+ assertNull("No LoggerContext should have been returned", ctx);
+ }
}
@Test
public void testErrorNullClassLoader() throws Exception {
- final LoggerContext ctx = Configurator.initialize("Test1", null, "target/test-classes/log4j2-config.xml");
- assertNull("No LoggerContext should have been returned", ctx);
+ try (final LoggerContext ctx = Configurator.initialize("Test1", null,
+ "target/test-classes/log4j2-config.xml")) {
+ assertNull("No LoggerContext should have been returned", ctx);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java
index 99d7518..61ce701 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java
@@ -49,8 +49,9 @@ public class ConfigurationAssemblerTest {
final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
CustomConfigurationFactory.addTestFixtures("config name", builder);
final Configuration configuration = builder.build();
- Configurator.initialize(configuration);
- validate(configuration);
+ try (LoggerContext ctx = Configurator.initialize(configuration)) {
+ validate(configuration);
+ }
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java
index 52d866b..087eaa0 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilterTest.java
@@ -74,17 +74,19 @@ public class DynamicThresholdFilterTest {
@Test
public void testConfig() {
- final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-dynamicfilter.xml");
- final Configuration config = ctx.getConfiguration();
- final Filter filter = config.getFilter();
- assertNotNull("No DynamicThresholdFilter", filter);
- assertTrue("Not a DynamicThresholdFilter", filter instanceof DynamicThresholdFilter);
- final DynamicThresholdFilter dynamic = (DynamicThresholdFilter) filter;
- final String key = dynamic.getKey();
- assertNotNull("Key is null", key);
- assertEquals("Incorrect key value", "loginId", key);
- final Map<String, Level> map = dynamic.getLevelMap();
- assertNotNull("Map is null", map);
- assertEquals("Incorrect number of map elements", 1, map.size());
+ try (final LoggerContext ctx = Configurator.initialize("Test1",
+ "target/test-classes/log4j2-dynamicfilter.xml")) {
+ final Configuration config = ctx.getConfiguration();
+ final Filter filter = config.getFilter();
+ assertNotNull("No DynamicThresholdFilter", filter);
+ assertTrue("Not a DynamicThresholdFilter", filter instanceof DynamicThresholdFilter);
+ final DynamicThresholdFilter dynamic = (DynamicThresholdFilter) filter;
+ final String key = dynamic.getKey();
+ assertNotNull("Key is null", key);
+ assertEquals("Incorrect key value", "loginId", key);
+ final Map<String, Level> map = dynamic.getLevelMap();
+ assertNotNull("Map is null", map);
+ assertEquals("Incorrect number of map elements", 1, map.size());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsLookupTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsLookupTest.java
index d8c32b7..6150afd 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsLookupTest.java
@@ -21,8 +21,8 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
/**
- * Tests {@link org.apache.logging.log4j.core.lookup.MainMapLookup#MAIN_SINGLETON} from the command line, not a real JUnit
- * test.
+ * Tests {@link org.apache.logging.log4j.core.lookup.MainMapLookup#MAIN_SINGLETON} from the command line, not a real
+ * JUnit test.
*
* From an IDE or CLI: --file foo.txt
*
@@ -32,12 +32,9 @@ public class MainInputArgumentsLookupTest {
public static void main(final String[] args) {
MainMapLookup.setMainArguments(args);
- final LoggerContext ctx = Configurator.initialize(MainInputArgumentsLookupTest.class.getName(),
- "target/test-classes/log4j-lookup-main.xml");
- try {
+ try (final LoggerContext ctx = Configurator.initialize(MainInputArgumentsLookupTest.class.getName(),
+ "target/test-classes/log4j-lookup-main.xml")) {
LogManager.getLogger().error("this is an error message");
- } finally {
- Configurator.shutdown(ctx);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/afc7ccbd/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d85df23..1b0dcc6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,9 @@
</properties>
<body>
<release version="2.7.0" date="2016-MM-DD" description="GA Release 2.7.0">
+ <action issue="LOG4J2-1472" dev="ggregory" type="add" due-to="Gary Gregory">
+ Make org.apache.logging.log4j.core.LoggerContext implement Closeable.
+ </action>
<action issue="LOG4J2-1458" dev="ggregory" type="add" due-to="Gary Gregory">
[PatternLayout] Add an ANSI option to %message.
</action>