logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1521180 - in /logging/log4j/log4j2/trunk/log4j-core/src: main/java/org/apache/logging/log4j/core/pattern/ test/java/org/apache/logging/log4j/core/appender/ test/resources/
Date Mon, 09 Sep 2013 16:23:45 GMT
Author: ggregory
Date: Mon Sep  9 16:23:44 2013
New Revision: 1521180

URL: http://svn.apache.org/r1521180
Log:
[LOG4J2-319] Double stack trace logging when using %throwable in %style and %highlight.

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
  (with props)
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-319.xml   (with props)
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/HighlightConverter.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/HighlightConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/HighlightConverter.java?rev=1521180&r1=1521179&r2=1521180&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/HighlightConverter.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/HighlightConverter.java
Mon Sep  9 16:23:44 2013
@@ -180,10 +180,10 @@ public final class HighlightConverter ex
         return new HighlightConverter(formatters, createLevelStyleMap(options));
     }
 
-    private final List<PatternFormatter> patternFormatters;
-
     private final EnumMap<Level, String> levelStyles;
 
+    private final List<PatternFormatter> patternFormatters;
+
     /**
      * Construct the converter.
      *
@@ -211,4 +211,14 @@ public final class HighlightConverter ex
                 append(AnsiEscape.getDefaultStyle());
         }
     }
+
+    @Override
+    public boolean handlesThrowable() {
+        for (final PatternFormatter formatter : patternFormatters) {
+            if (formatter .handlesThrowable()) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java?rev=1521180&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
Mon Sep  9 16:23:44 2013
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.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.11\jansi-1.11.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"));
+        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 (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);
+        }
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleJira319Main.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-319.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-319.xml?rev=1521180&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-319.xml (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-319.xml Mon Sep  9 16:23:44
2013
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<!-- https://issues.apache.org/jira/browse/LOG4J2-180 -->
+<Configuration status="INFO">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{ISO8601} %highlight{[%t] %-5level: %msg%n%throwable}"
/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <Logger name="org.foo" level="DEBUG" />
+    <Root level="TRACE">
+      <AppenderRef ref="Console" />
+    </Root>
+  </Loggers>
+</Configuration>
\ No newline at end of file

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-319.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-319.xml
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message