logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1573203 - 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 Sat, 01 Mar 2014 17:40:27 GMT
Author: rgoers
Date: Sat Mar  1 17:40:26 2014
New Revision: 1573203

URL: http://svn.apache.org/r1573203
Log:
LOG4J2-496 - Allow header and footer to be specified as lookup patterns in PatternLayout.

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/OutputStreamManager.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/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/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/config/CustomConfigurationTest.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/src/changes/changes.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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -161,7 +161,8 @@ 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, null);
+        final Layout<String> layout = PatternLayout.createLayout("%d %p %C{1.} [%t]
%m%n", null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 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, null);
+        final PatternLayout layout = PatternLayout.createLayout("%d %C %L %m", null, null,
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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -91,7 +91,7 @@ public final class ConsoleAppender exten
             return null;
         }
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -139,7 +139,7 @@ public final class FileAppender extends 
             return null;
         }
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, 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/OutputStreamManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java?rev=1573203&r1=1573202&r2=1573203&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
Sat Mar  1 17:40:26 2014
@@ -29,25 +29,21 @@ public class OutputStreamManager extends
 
     private volatile OutputStream os;
 
-    private final byte[] footer;
-    private final byte[] header;
+    private final Layout<?> layout;
 
     protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?>
layout) {
         super(streamName);
         this.os = os;
+        this.layout = layout;
         if (layout != null) {
-            this.footer = layout.getFooter();
-            this.header = layout.getHeader();
-            if (this.header != null) {
+            byte[] header = layout.getHeader();
+            if (header != null) {
                 try {
                     this.os.write(header, 0, header.length);
                 } catch (final IOException ioe) {
                     LOGGER.error("Unable to write header", ioe);
                 }
             }
-        } else {
-            this.footer = null;
-            this.header = null;
         }
     }
 
@@ -70,6 +66,7 @@ public class OutputStreamManager extends
      */
     @Override
     public void releaseSub() {
+        byte[] footer = layout.getFooter();
         if (footer != null) {
             write(footer);
         }
@@ -89,6 +86,7 @@ public class OutputStreamManager extends
     }
 
     protected void setOutputStream(final OutputStream os) {
+        byte[] header = layout.getHeader();
         if (header != null) {
             try {
                 os.write(header, 0, header.length);

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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -150,7 +150,7 @@ public final class RandomAccessFileAppen
             return null;
         }
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -169,7 +169,7 @@ public final class RollingFileAppender e
         }
 
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -189,7 +189,7 @@ public final class RollingRandomAccessFi
         }
 
         if (layout == null) {
-            layout = PatternLayout.createLayout(null, null, null, null, null, null);
+            layout = PatternLayout.createLayout(null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -130,8 +130,8 @@ public final class ColumnConfig {
         }
         if (isPattern) {
             return new ColumnConfig(
-                    name, PatternLayout.createLayout(pattern, config, null, null, "false",
null), null, false, isUnicode,
-                    isClob
+                    name, PatternLayout.createLayout(pattern, config, null, null, "false",
null, null, null), null,
+                    false, isUnicode, isClob
             );
         }
 

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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -377,7 +377,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, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -49,7 +49,8 @@ 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, null);
+                PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}
- %msg%n", 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/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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -106,11 +106,13 @@ 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
+     * @param noConsoleNoAnsi
      *            If {@code "true"} (default) and {@link System#console()} is null, do not
output ANSI escape codes
+     * @param header
      */
     private PatternLayout(final Configuration config, final RegexReplacement replace, final
String pattern,
-                          final Charset charset, final boolean alwaysWriteExceptions, boolean
noConsoleNoAnsi) {
+                          final Charset charset, final boolean alwaysWriteExceptions, boolean
noConsoleNoAnsi,
+                          String header, String footer) {
         super(charset);
         this.replace = replace;
         this.conversionPattern = pattern;
@@ -119,6 +121,41 @@ public final class PatternLayout extends
         this.noConsoleNoAnsi = noConsoleNoAnsi;
         final PatternParser parser = createPatternParser(config);
         this.formatters = parser.parse(pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern,
this.alwaysWriteExceptions, this.noConsoleNoAnsi);
+        if (charset != null) {
+            if (header != null) {
+                setHeader(header.getBytes(charset));
+            }
+            if (footer != null) {
+                setFooter(footer.getBytes(charset));
+            }
+        } else {
+            if (header != null) {
+                setHeader(header.getBytes());
+            }
+            if (footer != null) {
+                setFooter(footer.getBytes());
+            }
+        }
+    }
+
+    @Override
+    public byte[] getHeader() {
+        byte [] header = super.getHeader();
+        if (header != null) {
+            return config.getStrSubstitutor().replace(new String(header, getCharset())).getBytes(getCharset());
+        } else {
+            return header;
+        }
+    }
+
+    @Override
+    public byte[] getFooter() {
+        byte [] footer = super.getFooter();
+        if (footer != null) {
+            return config.getStrSubstitutor().replace(new String(footer, getCharset())).getBytes(getCharset());
+        } else {
+            return footer;
+        }
     }
 
     /**
@@ -203,7 +240,7 @@ public final class PatternLayout extends
 
     /**
      * Create a pattern layout.
-     * 
+     *
      * @param pattern
      *            The pattern. If not specified, defaults to DEFAULT_CONVERSION_PATTERN.
      * @param config
@@ -225,12 +262,14 @@ 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("noConsoleNoAnsi") final String noConsoleNoAnsiStr) {
+            @PluginAttribute("alwaysWriteExceptions") final String always,
+            @PluginAttribute("noConsoleNoAnsi") final String noConsoleNoAnsiStr,
+            @PluginAttribute("header") final String header,
+            @PluginAttribute("footer") final String footer) {
         final Charset charset = Charsets.getSupportedCharset(charsetName);
         final boolean alwaysWriteExceptions = Booleans.parseBoolean(always, true);
         final boolean noConsoleNoAnsi = Booleans.parseBoolean(noConsoleNoAnsiStr, false);
         return new PatternLayout(config, replace, pattern == null ? DEFAULT_CONVERSION_PATTERN
: pattern, charset,
-                alwaysWriteExceptions, noConsoleNoAnsi);
+                alwaysWriteExceptions, noConsoleNoAnsi, header, footer);
     }
 }

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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 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, null);
+        final Layout<String> layout = PatternLayout.createLayout(null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 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, 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, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -37,7 +37,7 @@ public class OutputStreamAppenderTest {
 
     @Test
     public void testAppender() {
-        final Layout<String> layout = PatternLayout.createLayout(null, null, null,
null, null, null);
+        final Layout<String> layout = PatternLayout.createLayout(null, null, 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/config/CustomConfigurationTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java?rev=1573203&r1=1573202&r2=1573203&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
Sat Mar  1 17:40:26 2014
@@ -63,7 +63,7 @@ public class CustomConfigurationTest {
         final Configuration config = ctx.getConfiguration();
         assertTrue("Configuration is not an XMLConfiguration", config instanceof XMLConfiguration);
         Layout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN,
config, null,
-            null,null, null);
+            null,null, null, null, null);
         Appender appender = FileAppender.createAppender("target/test.log", "false", "false",
"File", "true",
             "false", "false", "4000", layout, null, "false", null, config);
         appender.start();

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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 2014
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.la
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
@@ -31,6 +32,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.util.Compare;
 import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.After;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -55,6 +57,11 @@ public class PatternLayoutTest {
         ctx.reconfigure();
     }
 
+    @After
+    public void after() {
+        ThreadContext.clear();
+    }
+
     LoggerContext ctx = (LoggerContext) LogManager.getContext();
 
     Logger root = ctx.getLogger("");
@@ -72,7 +79,8 @@ 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, null);
+        final PatternLayout layout = PatternLayout.createLayout(msgPattern, ctx.getConfiguration(),
null, null, 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 +142,8 @@ 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, null);
+        final PatternLayout layout = PatternLayout.createLayout(regexPattern, ctx.getConfiguration(),
null, null, 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 +153,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, 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 +170,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, null);
+                .createLayout("%d{UNIX} %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);
@@ -178,7 +187,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, 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);
@@ -191,4 +200,19 @@ public class PatternLayoutTest {
         System.out.println("event2=" + event2.getMillis());
     }
 
+    @Test
+    public void testHeaderFooter() throws Exception {
+        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
+        final PatternLayout layout = PatternLayout
+            .createLayout("%d{UNIX} %m", ctx.getConfiguration(), null, null, null, null,
"${ctx:header}", "${ctx:footer}");
+        ThreadContext.put("header", "Hello world Header");
+        ThreadContext.put("footer", "Hello world Footer");
+        final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
+            "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello,
world 1!"), null);
+        byte[] header = layout.getHeader();
+        assertNotNull("No header", header);
+        assertTrue("expected \"Hello world Header\", actual \"" + new String(header) + "\"",
new String(header).equals(new String("Hello world Header")));
+    }
+
+
 }

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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 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, null);
+        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 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, null);
+        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, 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=1573203&r1=1573202&r2=1573203&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
Sat Mar  1 17:40:26 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, null);
+        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null,
null, null, null, null);
         final ConsoleAppender console =
                 ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false",
"true");
         console.start();

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1573203&r1=1573202&r2=1573203&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Mar  1 17:40:26 2014
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-rc2?" date="2014-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-496" dev="rgoers" type="update">
+        Allow header and footer to be specified as lookup patterns in PatternLayout.
+      </action>
       <action issue="LOG4J2-499" dev="rgoers"  type="fix">
         Add equals and hashcode to Log4jLogEvent.
       </action>



Mime
View raw message