logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1557790 - in /logging/log4j/log4j2/trunk: log4j-1.2-api/src/test/java/org/apache/log4j/ log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ log4j-core/sr...
Date Mon, 13 Jan 2014 17:49:01 GMT
Author: ggregory
Date: Mon Jan 13 17:49:00 2014
New Revision: 1557790

URL: http://svn.apache.org/r1557790
Log:
[LOG4J2-413] PatternLayout option to not output ANSI escape codes if no Console is available.

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiConverter.java   (with props)
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java   (with props)
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-no-ansi.xml   (with props)
Modified:
    logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
    logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/HighlightConverter.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-ansi.xml

Modified: logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java Mon Jan 13 17:49:00 2014
@@ -161,7 +161,7 @@ public class CategoryTest {
     @Test
     public void testClassName() {
         final Category category = Category.getInstance("TestCategory");
-        final Layout<String> layout = PatternLayout.createLayout("%d %p %C{1.} [%t] %m%n", null, null, null, null);
+        final Layout<String> layout = PatternLayout.createLayout("%d %p %C{1.} [%t] %m%n", null, null, null, null, null);
         final ListAppender appender = new ListAppender("List2", null, layout, false, false);
         appender.start();
         category.setAdditivity(false);

Modified: logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java Mon Jan 13 17:49:00 2014
@@ -456,7 +456,7 @@ public class LoggerTest {
     @Test
     @SuppressWarnings("deprecation")
     public void testLog() {
-        final PatternLayout layout = PatternLayout.createLayout("%d %C %L %m", null, null, null, null);
+        final PatternLayout layout = PatternLayout.createLayout("%d %C %L %m", null, null, null, null, null);
         final ListAppender appender = new ListAppender("List", null, layout, false, false);
         appender.start();
         final Logger root = Logger.getRootLogger();

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java Mon Jan 13 17:49:00 2014
@@ -91,7 +91,7 @@ public final class ConsoleAppender exten
             return null;
         }
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, null, null, null, null);
         }
         final boolean isFollow = Boolean.parseBoolean(follow);
         final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java Mon Jan 13 17:49:00 2014
@@ -139,7 +139,7 @@ public final class FileAppender extends 
             return null;
         }
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, null, null, null, null);
         }
 
         final FileManager manager = FileManager.getFileManager(fileName, isAppend, isLocking, isBuffered, advertiseURI,

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java Mon Jan 13 17:49:00 2014
@@ -150,7 +150,7 @@ public final class RandomAccessFileAppen
             return null;
         }
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, null, null, null, null);
         }
         final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager(
                 fileName, isAppend, isFlush, bufferSize, advertiseURI, layout

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java Mon Jan 13 17:49:00 2014
@@ -169,7 +169,7 @@ public final class RollingFileAppender e
         }
 
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, null, null, null, null);
         }
 
         final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, isAppend,

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java Mon Jan 13 17:49:00 2014
@@ -189,7 +189,7 @@ public final class RollingRandomAccessFi
         }
 
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, null, null, null, null);
         }
 
 

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java Mon Jan 13 17:49:00 2014
@@ -130,7 +130,7 @@ public final class ColumnConfig {
         }
         if (isPattern) {
             return new ColumnConfig(
-                    name, PatternLayout.createLayout(pattern, config, null, null, "false"), null, false, isUnicode,
+                    name, PatternLayout.createLayout(pattern, config, null, null, "false", null), null, false, isUnicode,
                     isClob
             );
         }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java Mon Jan 13 17:49:00 2014
@@ -62,7 +62,7 @@ public class PatternProcessor {
         final PatternParser parser = createPatternParser();
         final List<PatternConverter> converters = new ArrayList<PatternConverter>();
         final List<FormattingInfo> fields = new ArrayList<FormattingInfo>();
-        parser.parse(pattern, converters, fields);
+        parser.parse(pattern, converters, fields, false);
         final FormattingInfo[] infoArray = new FormattingInfo[fields.size()];
         patternFields = fields.toArray(infoArray);
         final ArrayPatternConverter[] converterArray = new ArrayPatternConverter[converters.size()];

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java Mon Jan 13 17:49:00 2014
@@ -314,7 +314,7 @@ public class BaseConfiguration extends A
         setName(DefaultConfiguration.DEFAULT_NAME);
         final Layout<? extends Serializable> layout =
                 PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n",
-                        null, null, null, null);
+                        null, null, null, null, null);
         final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false",
             "true");
         appender.start();

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java Mon Jan 13 17:49:00 2014
@@ -49,7 +49,7 @@ public class DefaultConfiguration extend
 
         setName(DEFAULT_NAME);
         final Layout<? extends Serializable> layout =
-                PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n", null, null, null, null);
+                PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n", null, null, null, null, null);
         final Appender appender =
                 ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
         appender.start();

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java Mon Jan 13 17:49:00 2014
@@ -95,6 +95,8 @@ public final class PatternLayout extends
 
     private final boolean alwaysWriteExceptions;
 
+    private final boolean noConsoleNoAnsi;
+
     /**
      * Constructs a EnhancedPatternLayout using the supplied conversion pattern.
      *
@@ -104,16 +106,19 @@ public final class PatternLayout extends
      * @param charset The character set.
      * @param alwaysWriteExceptions Whether or not exceptions should always be handled in this pattern (if {@code true},
      *                         exceptions will be written even if the pattern does not specify so).
+     * @param noConsoleNoAnsiStr
+     *            If {@code "true"} (default) and {@link System#console()} is null, do not output ANSI escape codes
      */
     private PatternLayout(final Configuration config, final RegexReplacement replace, final String pattern,
-                          final Charset charset, final boolean alwaysWriteExceptions) {
+                          final Charset charset, final boolean alwaysWriteExceptions, boolean noConsoleNoAnsi) {
         super(charset);
         this.replace = replace;
         this.conversionPattern = pattern;
         this.config = config;
         this.alwaysWriteExceptions = alwaysWriteExceptions;
+        this.noConsoleNoAnsi = noConsoleNoAnsi;
         final PatternParser parser = createPatternParser(config);
-        formatters = parser.parse(pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern, this.alwaysWriteExceptions);
+        this.formatters = parser.parse(pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern, this.alwaysWriteExceptions, this.noConsoleNoAnsi);
     }
 
     /**
@@ -129,7 +134,7 @@ public final class PatternLayout extends
             return;
         }
         final PatternParser parser = createPatternParser(this.config);
-        formatters = parser.parse(pattern, this.alwaysWriteExceptions);
+        formatters = parser.parse(pattern, this.alwaysWriteExceptions, this.noConsoleNoAnsi);
     }
 
     public String getConversionPattern() {
@@ -198,13 +203,20 @@ public final class PatternLayout extends
 
     /**
      * Create a pattern layout.
-     *
-     * @param pattern The pattern. If not specified, defaults to DEFAULT_CONVERSION_PATTERN.
-     * @param config The Configuration. Some Converters require access to the Interpolator.
-     * @param replace A Regex replacement String.
-     * @param charsetName The character set.
-     * @param always If {@code "true"} (default) exceptions are always written even if the pattern contains no exception
-     *               tokens.
+     * 
+     * @param pattern
+     *            The pattern. If not specified, defaults to DEFAULT_CONVERSION_PATTERN.
+     * @param config
+     *            The Configuration. Some Converters require access to the Interpolator.
+     * @param replace
+     *            A Regex replacement String.
+     * @param charsetName
+     *            The character set.
+     * @param always
+     *            If {@code "true"} (default) exceptions are always written even if the pattern contains no exception
+     *            tokens.
+     * @param noConsoleNoAnsiStr
+     *            If {@code "true"} (default is false) and {@link System#console()} is null, do not output ANSI escape codes
      * @return The PatternLayout.
      */
     @PluginFactory
@@ -213,11 +225,12 @@ public final class PatternLayout extends
             @PluginConfiguration final Configuration config,
             @PluginElement("Replace") final RegexReplacement replace,
             @PluginAttribute("charset") final String charsetName,
-            @PluginAttribute("alwaysWriteExceptions") final String always) {
+            @PluginAttribute("alwaysWriteExceptions") final String always, 
+            @PluginAttribute("noConsoleNoAnsi") final String noConsoleNoAnsiStr) {
         final Charset charset = Charsets.getSupportedCharset(charsetName);
         final boolean alwaysWriteExceptions = Booleans.parseBoolean(always, true);
-        return new PatternLayout(
-                config, replace, pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern, charset, alwaysWriteExceptions
-        );
+        final boolean noConsoleNoAnsi = Booleans.parseBoolean(noConsoleNoAnsiStr, false);
+        return new PatternLayout(config, replace, pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern, charset,
+                alwaysWriteExceptions, noConsoleNoAnsi);
     }
 }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java Mon Jan 13 17:49:00 2014
@@ -125,7 +125,7 @@ public class RFC5424Layout extends Abstr
                           final boolean useTLSMessageFormat, final LoggerFields[] loggerFields) {
         super(charset);
         final PatternParser exceptionParser = createPatternParser(config, ThrowablePatternConverter.class);
-        exceptionFormatters = exceptionPattern == null ? null : exceptionParser.parse(exceptionPattern, false);
+        exceptionFormatters = exceptionPattern == null ? null : exceptionParser.parse(exceptionPattern, false, false);
         this.facility = facility;
         this.defaultId = id == null ? DEFAULT_ID : id;
         this.enterpriseNumber = ein;
@@ -202,7 +202,7 @@ public class RFC5424Layout extends Abstr
                     final PatternParser fieldParser = createPatternParser(config, null);
 
                     for (final Map.Entry<String, String> entry : fields.entrySet()) {
-                        final List<PatternFormatter> formatters = fieldParser.parse(entry.getValue(), false);
+                        final List<PatternFormatter> formatters = fieldParser.parse(entry.getValue(), false, false);
                         sdParams.put(entry.getKey(), formatters);
                     }
                     final FieldFormatter fieldFormatter = new FieldFormatter(sdParams,

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java Mon Jan 13 17:49:00 2014
@@ -29,7 +29,7 @@ import org.apache.logging.log4j.core.lay
 /**
  * Style pattern converter. Adds ANSI color styling to the result of the enclosed pattern.
  */
-public abstract class AbstractStyleNameConverter extends LogEventPatternConverter {
+public abstract class AbstractStyleNameConverter extends LogEventPatternConverter /*TODO: implements AnsiConverter*/ {
 
     private final List<PatternFormatter> formatters;
 

Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiConverter.java?rev=1557790&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiConverter.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiConverter.java Mon Jan 13 17:49:00 2014
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.pattern;
+
+/**
+ * Marks classes that implement ANSI escape code convertions.
+ */
+interface AnsiConverter {
+    // a marker interface, empty.
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AnsiConverter.java
------------------------------------------------------------------------------
    svn:keywords = Id

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=1557790&r1=1557789&r2=1557790&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 Jan 13 17:49:00 2014
@@ -70,7 +70,7 @@ import org.apache.logging.log4j.core.lay
  */
 @Plugin(name = "highlight", category = "Converter")
 @ConverterKeys({ "highlight" })
-public final class HighlightConverter extends LogEventPatternConverter {
+public final class HighlightConverter extends LogEventPatternConverter implements AnsiConverter {
 
     private static final EnumMap<Level, String> DEFAULT_STYLES = new EnumMap<Level, String>(Level.class);
 
@@ -132,7 +132,10 @@ public final class HighlightConverter ex
         if (options.length < 2) {
             return DEFAULT_STYLES;
         }
-        final Map<String, String> styles = AnsiEscape.createMap(options[1], new String[] {STYLE_KEY});
+        // Feels like a hack. Should String[] options change to a Map<String,String>?
+        String string = options[1].replaceAll(PatternParser.NO_CONSOLE_NO_ANSI + "=(true|false)", "");
+        //
+        final Map<String, String> styles = AnsiEscape.createMap(string, new String[] {STYLE_KEY});
         final EnumMap<Level, String> levelStyles = new EnumMap<Level, String>(DEFAULT_STYLES);
         for (final Map.Entry<String, String> entry : styles.entrySet()) {
             final String key = entry.getKey().toUpperCase(Locale.ENGLISH);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java Mon Jan 13 17:49:00 2014
@@ -53,6 +53,7 @@ public final class LiteralPatternConvert
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
         toAppendTo.append(substitute ? config.getStrSubstitutor().replace(event, literal) : literal);
     }
+    
     /**
      * {@inheritDoc}
      */

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java Mon Jan 13 17:49:00 2014
@@ -32,12 +32,15 @@ import org.apache.logging.log4j.core.hel
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
- * Most of the work of the {@link org.apache.logging.log4j.core.layout.PatternLayout} class
- * is delegated to the PatternParser class.
- * <p>It is this class that parses conversion patterns and creates
- * a chained list of {@link PatternConverter PatternConverters}.
+ * Most of the work of the {@link org.apache.logging.log4j.core.layout.PatternLayout} class is delegated to the
+ * PatternParser class.
+ * <p>
+ * It is this class that parses conversion patterns and creates a chained list of {@link PatternConverter
+ * PatternConverters}.
  */
 public final class PatternParser {
+    static final String NO_CONSOLE_NO_ANSI = "noConsoleNoAnsi";
+
     /**
      * Escape character for format specifier.
      */
@@ -83,10 +86,11 @@ public final class PatternParser {
 
     private final Map<String, Class<PatternConverter>> converterRules;
 
-
     /**
      * Constructor.
-     * @param converterKey The type of converters that will be used.
+     * 
+     * @param converterKey
+     *            The type of converters that will be used.
      */
     public PatternParser(final String converterKey) {
         this(null, converterKey, null, null);
@@ -94,9 +98,13 @@ public final class PatternParser {
 
     /**
      * Constructor.
-     * @param config The current Configuration.
-     * @param converterKey The key to lookup the converters.
-     * @param expected The expected base Class of each Converter.
+     * 
+     * @param config
+     *            The current Configuration.
+     * @param converterKey
+     *            The key to lookup the converters.
+     * @param expected
+     *            The expected base Class of each Converter.
      */
     public PatternParser(final Configuration config, final String converterKey, final Class<?> expected) {
         this(config, converterKey, expected, null);
@@ -104,13 +112,18 @@ public final class PatternParser {
 
     /**
      * Constructor.
-     * @param config The current Configuration.
-     * @param converterKey The key to lookup the converters.
-     * @param expectedClass The expected base Class of each Converter.
-     * @param filterClass Filter the returned plugins after calling the plugin manager.
+     * 
+     * @param config
+     *            The current Configuration.
+     * @param converterKey
+     *            The key to lookup the converters.
+     * @param expectedClass
+     *            The expected base Class of each Converter.
+     * @param filterClass
+     *            Filter the returned plugins after calling the plugin manager.
      */
     public PatternParser(final Configuration config, final String converterKey, final Class<?> expectedClass,
-                         final Class<?> filterClass) {
+            final Class<?> filterClass) {
         this.config = config;
         final PluginManager manager = new PluginManager(converterKey, expectedClass);
         manager.collectPlugins();
@@ -120,7 +133,7 @@ public final class PatternParser {
         for (final PluginType<?> type : plugins.values()) {
             try {
                 @SuppressWarnings("unchecked")
-                final Class<PatternConverter> clazz = (Class<PatternConverter>)type.getPluginClass();
+                final Class<PatternConverter> clazz = (Class<PatternConverter>) type.getPluginClass();
                 if (filterClass != null && !filterClass.isAssignableFrom(clazz)) {
                     continue;
                 }
@@ -138,15 +151,16 @@ public final class PatternParser {
     }
 
     public List<PatternFormatter> parse(final String pattern) {
-        return parse(pattern, false);
+        return parse(pattern, false, false);
     }
 
-    public List<PatternFormatter> parse(final String pattern, final boolean alwaysWriteExceptions) {
+    public List<PatternFormatter> parse(final String pattern, final boolean alwaysWriteExceptions,
+            boolean noConsoleNoAnsi) {
         final List<PatternFormatter> list = new ArrayList<PatternFormatter>();
         final List<PatternConverter> converters = new ArrayList<PatternConverter>();
         final List<FormattingInfo> fields = new ArrayList<FormattingInfo>();
 
-        parse(pattern, converters, fields);
+        parse(pattern, converters, fields, noConsoleNoAnsi);
 
         final Iterator<FormattingInfo> fieldIter = fields.iterator();
         boolean handlesThrowable = false;
@@ -178,29 +192,33 @@ public final class PatternParser {
     /**
      * Extract the converter identifier found at position i.
      * <p/>
-     * After this function returns, the variable i will point to the
-     * first char after the end of the converter identifier.
+     * After this function returns, the variable i will point to the first char after the end of the converter
+     * identifier.
      * <p/>
-     * If i points to a char which is not a character acceptable at the
-     * start of a unicode identifier, the value null is returned.
-     *
-     * @param lastChar       last processed character.
-     * @param pattern        format string.
-     * @param i              current index into pattern format.
-     * @param convBuf        buffer to receive conversion specifier.
-     * @param currentLiteral literal to be output in case format specifier in unrecognized.
+     * If i points to a char which is not a character acceptable at the start of a unicode identifier, the value null is
+     * returned.
+     * 
+     * @param lastChar
+     *            last processed character.
+     * @param pattern
+     *            format string.
+     * @param i
+     *            current index into pattern format.
+     * @param convBuf
+     *            buffer to receive conversion specifier.
+     * @param currentLiteral
+     *            literal to be output in case format specifier in unrecognized.
      * @return position in pattern after converter.
      */
-    private static int extractConverter(
-        final char lastChar, final String pattern, int i, final StringBuilder convBuf,
-        final StringBuilder currentLiteral) {
+    private static int extractConverter(final char lastChar, final String pattern, int i, final StringBuilder convBuf,
+            final StringBuilder currentLiteral) {
         convBuf.setLength(0);
 
         // When this method is called, lastChar points to the first character of the
         // conversion word. For example:
-        // For "%hello"     lastChar = 'h'
-        // For "%-5hello"   lastChar = 'h'
-        //System.out.println("lastchar is "+lastChar);
+        // For "%hello" lastChar = 'h'
+        // For "%-5hello" lastChar = 'h'
+        // System.out.println("lastchar is "+lastChar);
         if (!Character.isUnicodeIdentifierStart(lastChar)) {
             return i;
         }
@@ -218,10 +236,13 @@ public final class PatternParser {
 
     /**
      * Extract options.
-     *
-     * @param pattern conversion pattern.
-     * @param i       start of options.
-     * @param options array to receive extracted options
+     * 
+     * @param pattern
+     *            conversion pattern.
+     * @param i
+     *            start of options.
+     * @param options
+     *            array to receive extracted options
      * @return position in pattern after options.
      */
     private static int extractOptions(final String pattern, int i, final List<String> options) {
@@ -256,13 +277,18 @@ public final class PatternParser {
 
     /**
      * Parse a format specifier.
-     *
-     * @param pattern           pattern to parse.
-     * @param patternConverters list to receive pattern converters.
-     * @param formattingInfos   list to receive field specifiers corresponding to pattern converters.
+     * 
+     * @param pattern
+     *            pattern to parse.
+     * @param patternConverters
+     *            list to receive pattern converters.
+     * @param formattingInfos
+     *            list to receive field specifiers corresponding to pattern converters.
+     * @param noConsoleNoAnsi
+     *            TODO
      */
     public void parse(final String pattern, final List<PatternConverter> patternConverters,
-            final List<FormattingInfo> formattingInfos) {
+            final List<FormattingInfo> formattingInfos, final boolean noConsoleNoAnsi) {
         if (pattern == null) {
             throw new NullPointerException("pattern");
         }
@@ -279,129 +305,125 @@ public final class PatternParser {
             c = pattern.charAt(i++);
 
             switch (state) {
-                case LITERAL_STATE:
+            case LITERAL_STATE:
+
+                // In literal state, the last char is always a literal.
+                if (i == patternLength) {
+                    currentLiteral.append(c);
+
+                    continue;
+                }
 
-                    // In literal state, the last char is always a literal.
-                    if (i == patternLength) {
+                if (c == ESCAPE_CHAR) {
+                    // peek at the next char.
+                    switch (pattern.charAt(i)) {
+                    case ESCAPE_CHAR:
                         currentLiteral.append(c);
+                        i++; // move pointer
 
-                        continue;
-                    }
+                        break;
+
+                    default:
 
-                    if (c == ESCAPE_CHAR) {
-                        // peek at the next char.
-                        switch (pattern.charAt(i)) {
-                            case ESCAPE_CHAR:
-                                currentLiteral.append(c);
-                                i++; // move pointer
-
-                                break;
-
-                            default:
-
-                                if (currentLiteral.length() != 0) {
-                                    patternConverters.add(new LiteralPatternConverter(config,
-                                        currentLiteral.toString()));
-                                    formattingInfos.add(FormattingInfo.getDefault());
-                                }
-
-                                currentLiteral.setLength(0);
-                                currentLiteral.append(c); // append %
-                                state = ParserState.CONVERTER_STATE;
-                                formattingInfo = FormattingInfo.getDefault();
+                        if (currentLiteral.length() != 0) {
+                            patternConverters.add(new LiteralPatternConverter(config, currentLiteral.toString()));
+                            formattingInfos.add(FormattingInfo.getDefault());
                         }
-                    } else {
-                        currentLiteral.append(c);
+
+                        currentLiteral.setLength(0);
+                        currentLiteral.append(c); // append %
+                        state = ParserState.CONVERTER_STATE;
+                        formattingInfo = FormattingInfo.getDefault();
                     }
+                } else {
+                    currentLiteral.append(c);
+                }
 
-                    break;
+                break;
 
-                case CONVERTER_STATE:
-                    currentLiteral.append(c);
+            case CONVERTER_STATE:
+                currentLiteral.append(c);
 
-                    switch (c) {
-                        case '-':
-                            formattingInfo =
-                                new FormattingInfo(true, formattingInfo.getMinLength(),
-                                    formattingInfo.getMaxLength());
-                            break;
-
-                        case '.':
-                            state = ParserState.DOT_STATE;
-                            break;
-
-                        default:
-
-                            if (c >= '0' && c <= '9') {
-                                formattingInfo = new FormattingInfo(formattingInfo.isLeftAligned(), c - '0',
-                                        formattingInfo.getMaxLength());
-                                state = ParserState.MIN_STATE;
-                            } else {
-                                i = finalizeConverter(c, pattern, i, currentLiteral, formattingInfo,
-                                        converterRules, patternConverters, formattingInfos);
-
-                                // Next pattern is assumed to be a literal.
-                                state = ParserState.LITERAL_STATE;
-                                formattingInfo = FormattingInfo.getDefault();
-                                currentLiteral.setLength(0);
-                            }
-                    } // switch
+                switch (c) {
+                case '-':
+                    formattingInfo = new FormattingInfo(true, formattingInfo.getMinLength(),
+                            formattingInfo.getMaxLength());
+                    break;
 
+                case '.':
+                    state = ParserState.DOT_STATE;
                     break;
 
-                case MIN_STATE:
-                    currentLiteral.append(c);
+                default:
 
                     if (c >= '0' && c <= '9') {
-                        // Multiply the existing value and add the value of the number just encountered.
-                        formattingInfo = new FormattingInfo(formattingInfo.isLeftAligned(),
-                                formattingInfo.getMinLength() * DECIMAL + c - '0',
+                        formattingInfo = new FormattingInfo(formattingInfo.isLeftAligned(), c - '0',
                                 formattingInfo.getMaxLength());
-                    } else if (c == '.') {
-                        state = ParserState.DOT_STATE;
+                        state = ParserState.MIN_STATE;
                     } else {
-                        i = finalizeConverter(c, pattern, i, currentLiteral, formattingInfo,
-                                converterRules, patternConverters, formattingInfos);
+                        i = finalizeConverter(c, pattern, i, currentLiteral, formattingInfo, converterRules,
+                                patternConverters, formattingInfos, noConsoleNoAnsi);
+
+                        // Next pattern is assumed to be a literal.
                         state = ParserState.LITERAL_STATE;
                         formattingInfo = FormattingInfo.getDefault();
                         currentLiteral.setLength(0);
                     }
+                } // switch
 
-                    break;
+                break;
 
-                case DOT_STATE:
-                    currentLiteral.append(c);
+            case MIN_STATE:
+                currentLiteral.append(c);
 
-                    if (c >= '0' && c <= '9') {
-                        formattingInfo = new FormattingInfo(formattingInfo.isLeftAligned(),
-                            formattingInfo.getMinLength(), c - '0');
-                        state = ParserState.MAX_STATE;
-                    } else {
-                        LOGGER.error("Error occurred in position " + i
-                                + ".\n Was expecting digit, instead got char \"" + c + "\".");
+                if (c >= '0' && c <= '9') {
+                    // Multiply the existing value and add the value of the number just encountered.
+                    formattingInfo = new FormattingInfo(formattingInfo.isLeftAligned(), formattingInfo.getMinLength()
+                            * DECIMAL + c - '0', formattingInfo.getMaxLength());
+                } else if (c == '.') {
+                    state = ParserState.DOT_STATE;
+                } else {
+                    i = finalizeConverter(c, pattern, i, currentLiteral, formattingInfo, converterRules,
+                            patternConverters, formattingInfos, noConsoleNoAnsi);
+                    state = ParserState.LITERAL_STATE;
+                    formattingInfo = FormattingInfo.getDefault();
+                    currentLiteral.setLength(0);
+                }
 
-                        state = ParserState.LITERAL_STATE;
-                    }
+                break;
 
-                    break;
+            case DOT_STATE:
+                currentLiteral.append(c);
 
-                case MAX_STATE:
-                    currentLiteral.append(c);
+                if (c >= '0' && c <= '9') {
+                    formattingInfo = new FormattingInfo(formattingInfo.isLeftAligned(), formattingInfo.getMinLength(),
+                            c - '0');
+                    state = ParserState.MAX_STATE;
+                } else {
+                    LOGGER.error("Error occurred in position " + i + ".\n Was expecting digit, instead got char \"" + c
+                            + "\".");
 
-                    if (c >= '0' && c <= '9') {
-                        // Multiply the existing value and add the value of the number just encountered.
-                        formattingInfo = new FormattingInfo(
-                                formattingInfo.isLeftAligned(), formattingInfo.getMinLength(),
-                                formattingInfo.getMaxLength() * DECIMAL + c - '0');
-                    } else {
-                        i = finalizeConverter(c, pattern, i, currentLiteral, formattingInfo,
-                                converterRules, patternConverters, formattingInfos);
-                        state = ParserState.LITERAL_STATE;
-                        formattingInfo = FormattingInfo.getDefault();
-                        currentLiteral.setLength(0);
-                    }
+                    state = ParserState.LITERAL_STATE;
+                }
 
-                    break;
+                break;
+
+            case MAX_STATE:
+                currentLiteral.append(c);
+
+                if (c >= '0' && c <= '9') {
+                    // Multiply the existing value and add the value of the number just encountered.
+                    formattingInfo = new FormattingInfo(formattingInfo.isLeftAligned(), formattingInfo.getMinLength(),
+                            formattingInfo.getMaxLength() * DECIMAL + c - '0');
+                } else {
+                    i = finalizeConverter(c, pattern, i, currentLiteral, formattingInfo, converterRules,
+                            patternConverters, formattingInfos, noConsoleNoAnsi);
+                    state = ParserState.LITERAL_STATE;
+                    formattingInfo = FormattingInfo.getDefault();
+                    currentLiteral.setLength(0);
+                }
+
+                break;
             } // switch
         }
 
@@ -414,26 +436,31 @@ public final class PatternParser {
 
     /**
      * Creates a new PatternConverter.
-     *
-     * @param converterId       converterId.
-     * @param currentLiteral    literal to be used if converter is unrecognized or following converter
-     *                          if converterId contains extra characters.
-     * @param rules             map of stock pattern converters keyed by format specifier.
-     * @param options           converter options.
+     * 
+     * @param converterId
+     *            converterId.
+     * @param currentLiteral
+     *            literal to be used if converter is unrecognized or following converter if converterId contains extra
+     *            characters.
+     * @param rules
+     *            map of stock pattern converters keyed by format specifier.
+     * @param options
+     *            converter options.
+     * @param noConsoleNoAnsi TODO
      * @return converter or null.
      */
     private PatternConverter createConverter(final String converterId, final StringBuilder currentLiteral,
-            final Map<String, Class<PatternConverter>> rules,
-            final List<String> options) {
+            final Map<String, Class<PatternConverter>> rules, final List<String> options, boolean noConsoleNoAnsi) {
         String converterName = converterId;
         Class<PatternConverter> converterClass = null;
 
+        if (rules == null) {
+            LOGGER.error("Null rules for [" + converterId + "]");
+            return null;
+        }
         for (int i = converterId.length(); i > 0 && converterClass == null; i--) {
             converterName = converterName.substring(0, i);
-
-            if (converterClass == null && rules != null) {
-                converterClass = rules.get(converterName);
-            }
+            converterClass = rules.get(converterName);
         }
 
         if (converterClass == null) {
@@ -441,13 +468,16 @@ public final class PatternParser {
             return null;
         }
 
+        if (AnsiConverter.class.isAssignableFrom(converterClass)) {
+            options.add(NO_CONSOLE_NO_ANSI + "=" + noConsoleNoAnsi);
+        }
         // Work around the regression bug in Class.getDeclaredMethods() in Oracle Java in version > 1.6.0_17:
         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6815786
         final Method[] methods = converterClass.getDeclaredMethods();
         Method newInstanceMethod = null;
         for (final Method method : methods) {
-            if (Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass().equals(converterClass) &&
-                    method.getName().equals("newInstance")) {
+            if (Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass().equals(converterClass)
+                    && method.getName().equals("newInstance")) {
                 if (newInstanceMethod == null) {
                     newInstanceMethod = method;
                 } else if (method.getReturnType().equals(newInstanceMethod.getReturnType())) {
@@ -462,7 +492,7 @@ public final class PatternParser {
         }
 
         final Class<?>[] parmTypes = newInstanceMethod.getParameterTypes();
-        final Object [] parms = parmTypes.length > 0 ? new Object[parmTypes.length] : null;
+        final Object[] parms = parmTypes.length > 0 ? new Object[parmTypes.length] : null;
 
         if (parms != null) {
             int i = 0;
@@ -474,8 +504,8 @@ public final class PatternParser {
                 } else if (clazz.isAssignableFrom(Configuration.class)) {
                     parms[i] = config;
                 } else {
-                    LOGGER.error("Unknown parameter type " + clazz.getName() + " for static newInstance method of " +
-                        converterClass.getName());
+                    LOGGER.error("Unknown parameter type " + clazz.getName() + " for static newInstance method of "
+                            + converterClass.getName());
                     errors = true;
                 }
                 ++i;
@@ -489,8 +519,7 @@ public final class PatternParser {
             final Object newObj = newInstanceMethod.invoke(null, parms);
 
             if (newObj instanceof PatternConverter) {
-                currentLiteral.delete(0, currentLiteral.length()
-                        - (converterId.length() - converterName.length()));
+                currentLiteral.delete(0, currentLiteral.length() - (converterId.length() - converterName.length()));
 
                 return (PatternConverter) newObj;
             } else {
@@ -505,21 +534,31 @@ public final class PatternParser {
 
     /**
      * Processes a format specifier sequence.
-     *
-     * @param c                 initial character of format specifier.
-     * @param pattern           conversion pattern
-     * @param i                 current position in conversion pattern.
-     * @param currentLiteral    current literal.
-     * @param formattingInfo    current field specifier.
-     * @param rules             map of stock pattern converters keyed by format specifier.
-     * @param patternConverters list to receive parsed pattern converter.
-     * @param formattingInfos   list to receive corresponding field specifier.
+     * 
+     * @param c
+     *            initial character of format specifier.
+     * @param pattern
+     *            conversion pattern
+     * @param i
+     *            current position in conversion pattern.
+     * @param currentLiteral
+     *            current literal.
+     * @param formattingInfo
+     *            current field specifier.
+     * @param rules
+     *            map of stock pattern converters keyed by format specifier.
+     * @param patternConverters
+     *            list to receive parsed pattern converter.
+     * @param formattingInfos
+     *            list to receive corresponding field specifier.
+     * @param noConsoleNoAnsi
+     *            TODO
      * @return position after format specifier sequence.
      */
-    private int finalizeConverter(final char c, final String pattern, int i,
-            final StringBuilder currentLiteral, final FormattingInfo formattingInfo,
-            final Map<String, Class<PatternConverter>> rules,
-            final List<PatternConverter> patternConverters, final List<FormattingInfo> formattingInfos) {
+    private int finalizeConverter(final char c, final String pattern, int i, final StringBuilder currentLiteral,
+            final FormattingInfo formattingInfo, final Map<String, Class<PatternConverter>> rules,
+            final List<PatternConverter> patternConverters, final List<FormattingInfo> formattingInfos,
+            final boolean noConsoleNoAnsi) {
         final StringBuilder convBuf = new StringBuilder();
         i = extractConverter(c, pattern, i, convBuf, currentLiteral);
 
@@ -528,7 +567,7 @@ public final class PatternParser {
         final List<String> options = new ArrayList<String>();
         i = extractOptions(pattern, i, options);
 
-        final PatternConverter pc = createConverter(converterId, currentLiteral, rules, options);
+        final PatternConverter pc = createConverter(converterId, currentLiteral, rules, options, noConsoleNoAnsi);
 
         if (pc == null) {
             StringBuilder msg;

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/StyleConverter.java Mon Jan 13 17:49:00 2014
@@ -27,15 +27,17 @@ import org.apache.logging.log4j.core.lay
  * Style pattern converter. Adds ANSI color styling to the result of the enclosed pattern.
  */
 @Plugin(name = "style", category = "Converter")
-@ConverterKeys({"style" })
-public final class StyleConverter extends LogEventPatternConverter {
+@ConverterKeys({ "style" })
+public final class StyleConverter extends LogEventPatternConverter implements AnsiConverter {
 
     /**
      * Gets an instance of the class.
-     *
-     * @param config The current Configuration.
-     * @param options pattern options, may be null.  If first element is "short",
-     *                only the first line of the throwable will be formatted.
+     * 
+     * @param config
+     *            The current Configuration.
+     * @param options
+     *            pattern options, may be null. If first element is "short", only the first line of the throwable will
+     *            be formatted.
      * @return instance of class.
      */
     public static StyleConverter newInstance(final Configuration config, final String[] options) {
@@ -51,29 +53,41 @@ public final class StyleConverter extend
             LOGGER.error("No style attributes provided");
             return null;
         }
-
         final PatternParser parser = PatternLayout.createPatternParser(config);
         final List<PatternFormatter> formatters = parser.parse(options[0]);
         final String style = AnsiEscape.createSequence(options[1].split("\\s*,\\s*"));
-        return new StyleConverter(formatters, style);
+        final boolean noConsoleNoAnsi = options.length > 2
+                && (PatternParser.NO_CONSOLE_NO_ANSI + "=true").equals(options[2]);
+        final boolean hideAnsi = noConsoleNoAnsi && System.console() == null;
+        return new StyleConverter(formatters, style, hideAnsi);
     }
 
     private final List<PatternFormatter> patternFormatters;
 
+    private final boolean noAnsi;
+
     private final String style;
 
+    private final String defaultStyle;
+
     /**
      * Constructs the converter.
-     * @param patternFormatters The PatternFormatters to generate the text to manipulate.
-     * @param style The style that should encapsulate the pattern.
+     * 
+     * @param patternFormatters
+     *            The PatternFormatters to generate the text to manipulate.
+     * @param style
+     *            The style that should encapsulate the pattern.
+     * @param noAnsi
+     *            If true, do not output ANSI escape codes. 
      */
-    private StyleConverter(final List<PatternFormatter> patternFormatters, final String style) {
+    private StyleConverter(final List<PatternFormatter> patternFormatters, final String style, boolean noAnsi) {
         super("style", "style");
         this.patternFormatters = patternFormatters;
         this.style = style;
+        this.defaultStyle = AnsiEscape.getDefaultStyle();
+        this.noAnsi = noAnsi;
     }
 
-
     /**
      * {@inheritDoc}
      */
@@ -85,14 +99,19 @@ public final class StyleConverter extend
         }
 
         if (buf.length() > 0) {
-            toAppendTo.append(style).append(buf.toString()).append(AnsiEscape.getDefaultStyle());
+            if (noAnsi) {
+                // faster to test and do this than setting style and defaultStyle to empty strings.
+                toAppendTo.append(buf.toString());
+            } else {
+                toAppendTo.append(style).append(buf.toString()).append(defaultStyle);
+            }
         }
     }
-    
+
     @Override
     public boolean handlesThrowable() {
         for (final PatternFormatter formatter : patternFormatters) {
-            if (formatter .handlesThrowable()) {
+            if (formatter.handlesThrowable()) {
                 return true;
             }
         }
@@ -110,8 +129,12 @@ public final class StyleConverter extend
         sb.append(super.toString());
         sb.append("[style=");
         sb.append(style);
+        sb.append(", defaultStyle=");
+        sb.append(defaultStyle);
         sb.append(", patternFormatters=");
         sb.append(patternFormatters);
+        sb.append(", noAnsi=");
+        sb.append(noAnsi);
         sb.append("]");
         return sb.toString();
     }

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java?rev=1557790&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderNoAnsiStyleLayoutMain.java Mon Jan 13 17:49:00 2014
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.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.11\jansi-1.11.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);
+
+    public static void main(final String[] args) {
+        // System.out.println(System.getProperty("java.class.path"));
+        String config = args.length == 0 ? "target/test-classes/log4j2-console-style-no-ansi.xml" : args[0];
+        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.");
+            LOG.error("Error message.", new IOException("test"));
+        } finally {
+            Configurator.shutdown(ctx);
+        }
+    }
+
+}

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

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

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java Mon Jan 13 17:49:00 2014
@@ -51,7 +51,7 @@ public class ConsoleAppenderTest {
     @Test
     public void testFollow() {
         final PrintStream ps = System.out;
-        final Layout<String> layout = PatternLayout.createLayout(null, null, null, null, null);
+        final Layout<String> layout = PatternLayout.createLayout(null, null, null, null, null, null);
         final ConsoleAppender app = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "true", "false");
         app.start();
         final LogEvent event = new Log4jLogEvent("TestLogger", null, ConsoleAppenderTest.class.getName(), Level.INFO,

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java Mon Jan 13 17:49:00 2014
@@ -74,7 +74,7 @@ public class FileAppenderTest {
     @Test
     public void testSmallestBufferSize() throws Exception {
         final Layout<String> layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, null, null,
-                null, null);
+                null, null, null);
         final String bufferSizeStr = "1";
         final FileAppender appender = FileAppender.createAppender(FILENAME, "true", "false", "test", "false", "false",
                 "false", bufferSizeStr, layout, null, "false", null, null);
@@ -168,7 +168,7 @@ public class FileAppenderTest {
 
     private static void writer(final boolean lock, final int count, final String name) throws Exception {
         final Layout<String> layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, null, null,
-                null, null);
+                null, null, null);
         final FileAppender app = FileAppender.createAppender(FILENAME, "true", Boolean.toString(lock), "test", "false",
                 "false", "false", null, layout, null, "false", null, null);
         app.start();

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java Mon Jan 13 17:49:00 2014
@@ -37,7 +37,7 @@ public class OutputStreamAppenderTest {
 
     @Test
     public void testAppender() {
-        final Layout<String> layout = PatternLayout.createLayout(null, null, null, null, null);
+        final Layout<String> layout = PatternLayout.createLayout(null, null, null, null, null, null);
         final InMemoryAppender app = new InMemoryAppender("test", layout, null, false);
         final LogEvent event = new Log4jLogEvent("TestLogger", null, OutputStreamAppenderTest.class.getName(), Level.INFO,
             new SimpleMessage("Test"), null);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java Mon Jan 13 17:49:00 2014
@@ -72,7 +72,7 @@ public class PatternLayoutTest {
         final String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
 
         // set up appender
-        final PatternLayout layout = PatternLayout.createLayout(msgPattern, ctx.getConfiguration(), null, null, null);
+        final PatternLayout layout = PatternLayout.createLayout(msgPattern, ctx.getConfiguration(), null, null, null, null);
         // FileOutputStream fos = new FileOutputStream(OUTPUT_FILE + "_mdc");
         final FileAppender appender = FileAppender.createAppender(OUTPUT_FILE + "_mdc", "false", "false", "File",
                 "false", "true", "false", null, layout, null, "false", null, null);
@@ -134,7 +134,7 @@ public class PatternLayoutTest {
     @Test
     public void testRegex() throws Exception {
         final LoggerContext ctx = (LoggerContext) LogManager.getContext();
-        final PatternLayout layout = PatternLayout.createLayout(regexPattern, ctx.getConfiguration(), null, null, null);
+        final PatternLayout layout = PatternLayout.createLayout(regexPattern, ctx.getConfiguration(), null, null, null, null);
         final LogEvent event = new Log4jLogEvent(this.getClass().getName(), null,
                 "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world!"), null);
         final byte[] result = layout.toByteArray(event);
@@ -144,7 +144,7 @@ public class PatternLayoutTest {
     private void testUnixTime(String pattern) throws Exception {
         final LoggerContext ctx = (LoggerContext) LogManager.getContext();
         final PatternLayout layout = PatternLayout.createLayout(pattern + " %m", ctx.getConfiguration(), null, null,
-                null);
+                null, null);
         final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
                 "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world 1!"), null);
         final byte[] result1 = layout.toByteArray(event1);
@@ -161,7 +161,7 @@ public class PatternLayoutTest {
     public void testUnixTime() throws Exception {
         final LoggerContext ctx = (LoggerContext) LogManager.getContext();
         final PatternLayout layout = PatternLayout
-                .createLayout("%d{UNIX} %m", ctx.getConfiguration(), null, null, null);
+                .createLayout("%d{UNIX} %m", ctx.getConfiguration(), null, null, null, null);
         final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
                 "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world 1!"), null);
         final byte[] result1 = layout.toByteArray(event1);
@@ -178,7 +178,7 @@ public class PatternLayoutTest {
     public void testUnixTimeMillis() throws Exception {
         final LoggerContext ctx = (LoggerContext) LogManager.getContext();
         final PatternLayout layout = PatternLayout.createLayout("%d{UNIX_MILLIS} %m", ctx.getConfiguration(), null,
-                null, null);
+                null, null, null);
         final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
                 "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world 1!"), null);
         final byte[] result1 = layout.toByteArray(event1);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/AbstractSocketServerTest.java Mon Jan 13 17:49:00 2014
@@ -111,7 +111,7 @@ public abstract class AbstractSocketServ
         appender.start();
         final ListAppender listApp = new ListAppender("Events", serverFilter, null, false, false);
         listApp.start();
-        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null);
+        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null, null);
         final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
         final Logger serverLogger = ctx.getLogger(this.getClass().getName());
         serverLogger.addAppender(console);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSQueueTest.java Mon Jan 13 17:49:00 2014
@@ -101,7 +101,7 @@ public class JMSQueueTest {
         final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
         final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
         listApp.start();
-        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null);
+        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null, null);
         final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
         console.start();
         final Logger serverLogger = ctx.getLogger(JMSTopicReceiver.class.getName());

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/JMSTopicTest.java Mon Jan 13 17:49:00 2014
@@ -101,7 +101,7 @@ public class JMSTopicTest {
         final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
         final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
         listApp.start();
-        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null);
+        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null, null);
         final ConsoleAppender console =
                 ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
         console.start();

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java Mon Jan 13 17:49:00 2014
@@ -55,8 +55,8 @@ public class PatternParserTest {
     private final String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
 
     private static String customPattern = "[%d{yyyyMMdd HH:mm:ss,SSS}] %-5p [%-25.25c{1}:%-4L] - %m%n";
-    private static String nestedPattern =
-        "%highlight{%d{dd MMM yyyy HH:mm:ss,SSS}{GMT+0} [%t] %-5level: %msg%n%throwable}";
+    private static String nestedPatternHighlight =
+            "%highlight{%d{dd MMM yyyy HH:mm:ss,SSS}{GMT+0} [%t] %-5level: %msg%n%throwable}";
 
     private static final String KEY = "Converter";
     private PatternParser parser;
@@ -108,21 +108,32 @@ public class PatternParserTest {
     }
 
     @Test
-    public void testNestedPattern() {
-        final List<PatternFormatter> formatters = parser.parse(nestedPattern);
+    public void testNestedPatternHighlight() {       
+        testNestedPatternHighlight(Level.TRACE, "\u001B[30m13");
+        testNestedPatternHighlight(Level.DEBUG, "\u001B[36m13");
+        testNestedPatternHighlight(Level.INFO, "\u001B[32m13");
+        testNestedPatternHighlight(Level.WARN, "\u001B[33m13");
+        testNestedPatternHighlight(Level.ERROR, "\u001B[1;31m13");
+        testNestedPatternHighlight(Level.FATAL, "\u001B[1;31m13");
+    }
+
+    private void testNestedPatternHighlight(Level level, String startLine) {
+        final List<PatternFormatter> formatters = parser.parse(nestedPatternHighlight);
         assertNotNull(formatters);
         final Throwable t = new Throwable();
-        final StackTraceElement[] elements = t.getStackTrace();
-        final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest", MarkerManager.getMarker("TEST"),
-                Logger.class.getName(), Level.INFO, new SimpleMessage("Hello, world"), null, null, null, "Thread1", elements[0],
-                System.currentTimeMillis());
+        final StackTraceElement[] stackTraceElement = t.getStackTrace();
+        final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest",
+                MarkerManager.getMarker("TEST"), Logger.class.getName(), level, new SimpleMessage("Hello, world"),
+                null, null, null, "Thread1", /*stackTraceElement[0]*/null, System.currentTimeMillis());
         final StringBuilder buf = new StringBuilder();
         for (final PatternFormatter formatter : formatters) {
             formatter.format(event, buf);
         }
         final String str = buf.toString();
-        final String expected = String.format("] INFO : Hello, world%s\u001B[m", Constants.LINE_SEP);
-        assertTrue("Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
+        final String expectedStart = startLine + " ";
+        final String expectedEnd = String.format("] %-5s: Hello, world%s\u001B[m", level, Constants.LINE_SEP);
+        assertTrue("Expected to start with: " + expectedStart + ". Actual: " + str, str.startsWith(expectedStart));
+        assertTrue("Expected to end with: \"" + expectedEnd + "\". Actual: \"" + str, str.endsWith(expectedEnd));
     }
 
 }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-ansi.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-ansi.xml?rev=1557790&r1=1557789&r2=1557790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-ansi.xml (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-ansi.xml Mon Jan 13 17:49:00 2014
@@ -1,19 +1,19 @@
 <?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
+  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
+  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.
+  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.
 
 -->
 <Configuration status="INFO">

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-no-ansi.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-no-ansi.xml?rev=1557790&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-no-ansi.xml (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-no-ansi.xml Mon Jan 13 17:49:00 2014
@@ -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.
+
+-->
+<Configuration status="INFO">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout noConsoleNoAnsi="true"
+        pattern="%style{%d{ISO8601}}{black} %style{[%t]}{blue} %style{%-5level:}{yellow} %style{%msg%n%throwable}{green}" />
+    </Console>
+  </Appenders>
+  <Loggers>
+    <Logger name="org.foo" level="DEBUG" />
+    <Root level="TRACE">
+      <AppenderRef ref="Console" />
+    </Root>
+  </Loggers>
+</Configuration>

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

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j2-console-style-no-ansi.xml
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message