You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/08/20 02:04:35 UTC

[1/8] logging-log4j2 git commit: [LOG4J2-1504] RollingFileAppender should be able to create files on-demand.

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure b842432cd -> 917afad56


[LOG4J2-1504] RollingFileAppender should be able to create files
on-demand.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a82794f0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a82794f0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a82794f0

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: a82794f06e3bc095ef0bca41b98c5d1ea915de76
Parents: 60649ef
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Aug 19 17:27:26 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Aug 19 17:27:26 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/appender/FileManager.java        |  12 +-
 .../core/appender/OutputStreamManager.java      |  18 +-
 .../core/appender/RollingFileAppender.java      | 372 ++++++++++++-------
 .../appender/rolling/RollingFileManager.java    |  50 ++-
 .../rolling/OnStartupTriggeringPolicyTest.java  |  10 +-
 .../rolling/RollingAppenderSizeTest.java        |  43 ++-
 .../rolling/RollingFileAppenderAccessTest.java  |  61 +--
 .../test/resources/log4j-rolling-7z-lazy.xml    |  59 +++
 .../test/resources/log4j-rolling-bzip2-lazy.xml |  60 +++
 .../resources/log4j-rolling-deflate-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-gz-lazy.xml    |  59 +++
 .../resources/log4j-rolling-pack200-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-xz-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-zip-lazy.xml   |  60 +++
 src/changes/changes.xml                         |   5 +-
 15 files changed, 791 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
index c71bd95..b8a559a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
@@ -45,6 +45,9 @@ public class FileManager extends OutputStreamManager {
     private final String advertiseURI;
     private final int bufferSize;
 
+    /**
+     * @deprecated
+     */
     @Deprecated
     protected FileManager(final String fileName, final OutputStream os, final boolean append, final boolean locking,
             final String advertiseURI, final Layout<? extends Serializable> layout, final int bufferSize,
@@ -53,7 +56,7 @@ public class FileManager extends OutputStreamManager {
     }
 
     /**
-     * @deprecated 
+     * @deprecated
      * @since 2.6 
      */
     @Deprecated
@@ -72,10 +75,10 @@ public class FileManager extends OutputStreamManager {
      * @throws IOException 
      * @since 2.7 
      */
-    protected FileManager(final String fileName, final boolean append, final boolean locking, final boolean lazyCreate,
+    protected FileManager(final String fileName, final OutputStream os, final boolean append, final boolean locking, final boolean lazyCreate,
             final String advertiseURI, final Layout<? extends Serializable> layout, final boolean writeHeader,
             final ByteBuffer buffer) throws IOException {
-        super(fileName, lazyCreate, layout, writeHeader, buffer);
+        super(os, fileName, lazyCreate, layout, writeHeader, buffer);
         this.isAppend = append;
         this.isLazyCreate = lazyCreate;
         this.isLocking = locking;
@@ -253,7 +256,8 @@ public class FileManager extends OutputStreamManager {
             try {
                 final int actualSize = data.bufferedIO ? data.bufferSize : Constants.ENCODER_BYTE_BUFFER_SIZE;
                 final ByteBuffer buffer = ByteBuffer.wrap(new byte[actualSize]);
-                return new FileManager(name, data.append, data.locking, data.lazyCreate, data.advertiseURI, data.layout,
+                final FileOutputStream fos = data.lazyCreate ? null : new FileOutputStream(file, data.append);
+                return new FileManager(name, fos, data.append, data.locking, data.lazyCreate, data.advertiseURI, data.layout,
                         writeHeader, buffer);
             } catch (final IOException ex) {
                 LOGGER.error("FileManager (" + name + ") " + ex, ex);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
index e707bea..d895dd5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
@@ -43,12 +43,6 @@ public class OutputStreamManager extends AbstractManager implements ByteBufferDe
     }
 
     /**
-     *
-     * @param os
-     * @param streamName
-     * @param layout
-     * @param writeHeader
-     * @param byteBuffer
      * @since 2.6
      * @deprecated
      */
@@ -72,17 +66,21 @@ public class OutputStreamManager extends AbstractManager implements ByteBufferDe
     }
 
     /**
-     * @param byteBuffer
      * @throws IOException 
      * @since 2.7
      */
-    protected OutputStreamManager(final String streamName, final boolean lazyCreate, final Layout<? extends Serializable> layout,
-            final boolean writeHeader, final ByteBuffer byteBuffer)
+    protected OutputStreamManager(OutputStream os, final String streamName, final boolean lazyCreate,
+            final Layout<? extends Serializable> layout, final boolean writeHeader, final ByteBuffer byteBuffer)
             throws IOException {
         super(streamName);
+        if (lazyCreate && os != null) {
+            LOGGER.error(
+                    "Invalid OutputStreamManager configuration for '{}': You cannot both set the OutputStream and request on-demand.",
+                    streamName);
+        }
         this.layout = layout;
         this.byteBuffer = Objects.requireNonNull(byteBuffer, "byteBuffer");
-        this.os = lazyCreate ? null : createOutputStream();
+        this.os = os;
         if (writeHeader && layout != null) {
             final byte[] header = layout.getHeader();
             if (header != null) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
index 01ef50d..dc830e3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
@@ -31,9 +31,12 @@ import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.core.net.Advertiser;
 import org.apache.logging.log4j.core.util.Booleans;
@@ -45,6 +48,215 @@ import org.apache.logging.log4j.core.util.Integers;
 @Plugin(name = "RollingFile", category = "Core", elementType = "appender", printObject = true)
 public final class RollingFileAppender extends AbstractOutputStreamAppender<RollingFileManager> {
 
+    /**
+     * Builds FileAppender instances.
+     * 
+     * @param <B>
+     *            This builder class
+     */
+    public static class Builder<B extends Builder<B>> extends AbstractOutputStreamAppender.Builder<B>
+            implements org.apache.logging.log4j.core.util.Builder<RollingFileAppender> {
+
+        @PluginBuilderAttribute
+        @Required
+        private String fileName;
+
+        @PluginBuilderAttribute
+        @Required
+        private String filePattern;
+
+        @PluginBuilderAttribute
+        private boolean append = true;
+
+        @PluginBuilderAttribute
+        private boolean locking;
+
+        @PluginElement("Policy") 
+        @Required
+        private TriggeringPolicy policy;
+        
+        @PluginElement("Strategy") 
+        private RolloverStrategy strategy;
+
+        @PluginBuilderAttribute
+        private boolean bufferedIo = true;
+
+        @PluginBuilderAttribute
+        private int bufferSize = DEFAULT_BUFFER_SIZE;
+
+        @PluginBuilderAttribute
+        private boolean advertise;
+
+        @PluginBuilderAttribute
+        private String advertiseUri;
+
+        @PluginBuilderAttribute
+        private boolean lazyCreate;
+
+        @PluginConfiguration
+        private Configuration config;
+
+        @Override
+        public RollingFileAppender build() {
+            // Even though some variables may be annotated with @Required, we must still perform validation here for
+            // call sites that build builders programmatically.
+            if (getName() == null) {
+                LOGGER.error("RollingFileAppender '{}': No name provided.", getName());
+                return null;
+            }
+
+            if (!bufferedIo && bufferSize > 0) {
+                LOGGER.warn("RollingFileAppender '{}': The bufferSize is set to {} but bufferedIO is not true", getName(), bufferSize);
+            }
+
+            if (fileName == null) {
+                LOGGER.error("RollingFileAppender '{}': No file name provided.", getName());
+                return null;
+            }
+
+            if (filePattern == null) {
+                LOGGER.error("RollingFileAppender '{}': No file name pattern provided.", getName());
+                return null;
+            }
+
+            if (policy == null) {
+                LOGGER.error("RollingFileAppender '{}': No TriggeringPolicy provided.", getName());
+                return null;
+            }
+
+            if (strategy == null) {
+                strategy = DefaultRolloverStrategy.createStrategy(null, null, null,
+                        String.valueOf(Deflater.DEFAULT_COMPRESSION), null, true, config);
+            }
+
+            if (strategy == null) {
+                strategy = DefaultRolloverStrategy.createStrategy(null, null, null,
+                        String.valueOf(Deflater.DEFAULT_COMPRESSION), null, true, config);
+            }
+
+            final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, append,
+                    bufferedIo, policy, strategy, advertiseUri, getLayout(), bufferSize, isImmediateFlush(),
+                    lazyCreate);
+            if (manager == null) {
+                return null;
+            }
+
+            manager.initialize();
+
+            return new RollingFileAppender(getName(), getLayout(), getFilter(), manager, fileName, filePattern,
+                    isIgnoreExceptions(), isImmediateFlush(), advertise ? config.getAdvertiser() : null);
+        }
+
+        public String getAdvertiseUri() {
+            return advertiseUri;
+        }
+
+        public int getBufferSize() {
+            return bufferSize;
+        }
+
+        public Configuration getConfig() {
+            return config;
+        }
+
+        public String getFileName() {
+            return fileName;
+        }
+
+        public boolean isAdvertise() {
+            return advertise;
+        }
+
+        public boolean isAppend() {
+            return append;
+        }
+
+        public boolean isBufferedIo() {
+            return bufferedIo;
+        }
+
+        public boolean isLazyCreate() {
+            return lazyCreate;
+        }
+
+        public boolean isLocking() {
+            return locking;
+        }
+
+        public B withAdvertise(final boolean advertise) {
+            this.advertise = advertise;
+            return asBuilder();
+        }
+
+        public B withAdvertiseUri(final String advertiseUri) {
+            this.advertiseUri = advertiseUri;
+            return asBuilder();
+        }
+
+        public B withAppend(final boolean append) {
+            this.append = append;
+            return asBuilder();
+        }
+
+        public B withBufferedIo(final boolean bufferedIo) {
+            this.bufferedIo = bufferedIo;
+            return asBuilder();
+        }
+
+        public B withBufferSize(final int bufferSize) {
+            this.bufferSize = bufferSize;
+            return asBuilder();
+        }
+
+        public B withConfig(final Configuration config) {
+            this.config = config;
+            return asBuilder();
+        }
+
+        public B withFileName(final String fileName) {
+            this.fileName = fileName;
+            return asBuilder();
+        }
+
+        public B withLazyCreate(final boolean lazyCreate) {
+            this.lazyCreate = lazyCreate;
+            return asBuilder();
+        }
+
+        public B withLocking(final boolean locking) {
+            this.locking = locking;
+            return asBuilder();
+        }
+
+        public String getFilePattern() {
+            return filePattern;
+        }
+
+        public TriggeringPolicy getPolicy() {
+            return policy;
+        }
+
+        public RolloverStrategy getStrategy() {
+            return strategy;
+        }
+
+        public B withFilePattern(String filePattern) {
+            this.filePattern = filePattern;
+            return asBuilder();
+        }
+
+        public B withPolicy(TriggeringPolicy policy) {
+            this.policy = policy;
+            return asBuilder();
+        }
+
+        public B withStrategy(RolloverStrategy strategy) {
+            this.strategy = strategy;
+            return asBuilder();
+        }
+
+    }
+    
     private static final int DEFAULT_BUFFER_SIZE = 8192;
 
     private final String fileName;
@@ -128,9 +340,10 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll
      * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
      *               they are propagated to the caller.
      * @param advertise "true" if the appender configuration should be advertised, "false" otherwise.
-     * @param advertiseURI The advertised URI which can be used to retrieve the file contents.
+     * @param advertiseUri The advertised URI which can be used to retrieve the file contents.
      * @param config The Configuration.
      * @return A RollingFileAppender.
+     * @deprecated Use {@link #newBuilder()}.
      */
     @Deprecated
     public static RollingFileAppender createAppender(
@@ -148,142 +361,35 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll
             final Filter filter,
             final String ignore,
             final String advertise,
-            final String advertiseURI,
+            final String advertiseUri,
             final Configuration config) {
             // @formatter:on
-
-        final boolean isAppend = Booleans.parseBoolean(append, true);
-        final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
-        final boolean isBuffered = Booleans.parseBoolean(bufferedIO, true);
-        final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
-        final boolean isAdvertise = Boolean.parseBoolean(advertise);
         final int bufferSize = Integers.parseInt(bufferSizeStr, DEFAULT_BUFFER_SIZE);
-        if (!isBuffered && bufferSize > 0) {
-            LOGGER.warn("The bufferSize is set to {} but bufferedIO is not true: {}", bufferSize, bufferedIO);
-        }
-        if (name == null) {
-            LOGGER.error("No name provided for FileAppender");
-            return null;
-        }
-
-        if (fileName == null) {
-            LOGGER.error("No filename was provided for FileAppender with name "  + name);
-            return null;
-        }
-
-        if (filePattern == null) {
-            LOGGER.error("No filename pattern provided for FileAppender with name "  + name);
-            return null;
-        }
-
-        if (policy == null) {
-            LOGGER.error("A TriggeringPolicy must be provided");
-            return null;
-        }
-
-        if (strategy == null) {
-            strategy = DefaultRolloverStrategy.createStrategy(null, null, null,
-                    String.valueOf(Deflater.DEFAULT_COMPRESSION), null, true, config);
-        }
-
-        if (layout == null) {
-            layout = PatternLayout.createDefaultLayout();
-        }
-
-        final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, isAppend,
-            isBuffered, policy, strategy, advertiseURI, layout, bufferSize, isFlush);
-        if (manager == null) {
-            return null;
-        }
-
-        manager.initialize();
-
-        return new RollingFileAppender(name, layout, filter, manager, fileName, filePattern,
-                ignoreExceptions, isFlush, isAdvertise ? config.getAdvertiser() : null);
+        // @formatter:off
+        return newBuilder()
+                .withAdvertise(Boolean.parseBoolean(advertise))
+                .withAdvertiseUri(advertiseUri)
+                .withAppend(Booleans.parseBoolean(append, true))
+                .withBufferedIo(Booleans.parseBoolean(bufferedIO, true))
+                .withBufferSize(bufferSize)
+                .withConfig(config)
+                .withFileName(fileName)
+                .withFilePattern(filePattern)
+                .withFilter(filter)
+                .withIgnoreExceptions(Booleans.parseBoolean(ignore, true))
+                .withImmediateFlush(Booleans.parseBoolean(immediateFlush, true))
+                .withLayout(layout)
+                .withLazyCreate(false)
+                .withLocking(false)
+                .withName(name)
+                .withPolicy(policy)
+                .withStrategy(strategy)
+                .build();
+        // @formatter:on
     }
 
-    /**
-     * Creates a RollingFileAppender.
-     * @param fileName The name of the file that is actively written to. (required).
-     * @param filePattern The pattern of the file name to use on rollover. (required).
-     * @param append If true, events are appended to the file. If false, the file
-     * is overwritten when opened. Defaults to "true"
-     * @param name The name of the Appender (required).
-     * @param bufferedIo When true, I/O will be buffered. Defaults to "true".
-     * @param bufferSize buffer size for buffered IO (default is 8192).
-     * @param immediateFlush When true, events are immediately flushed. Defaults to "true".
-     * @param policy The triggering policy. (required).
-     * @param strategy The rollover strategy. Defaults to DefaultRolloverStrategy.
-     * @param layout The layout to use (defaults to the default PatternLayout).
-     * @param filter The Filter or null.
-     * @param ignoreExceptions If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
-     *               they are propagated to the caller.
-     * @param advertise "true" if the appender configuration should be advertised, "false" otherwise.
-     * @param advertiseURI The advertised URI which can be used to retrieve the file contents.
-     * @param config The Configuration.
-     * @return A RollingFileAppender.
-     * @since 2.7
-     */
-    @PluginFactory
-    public static RollingFileAppender createAppender(
-            // @formatter:off
-            @PluginAttribute("fileName") final String fileName,
-            @PluginAttribute("filePattern") final String filePattern,
-            @PluginAttribute(value = "append", defaultBoolean = true) final boolean append,
-            @PluginAttribute("name") final String name,
-            @PluginAttribute(value = "bufferedIO", defaultBoolean = true) final boolean bufferedIo,
-            @PluginAttribute(value = "bufferSize", defaultInt = DEFAULT_BUFFER_SIZE) final int bufferSize,
-            @PluginAttribute(value = "immediateFlush" , defaultBoolean = true) final boolean immediateFlush,
-            @PluginElement("Policy") final TriggeringPolicy policy,
-            @PluginElement("Strategy") RolloverStrategy strategy,
-            @PluginElement("Layout") Layout<? extends Serializable> layout,
-            @PluginElement("Filter") final Filter filter,
-            @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions,
-            @PluginAttribute("advertise") final boolean advertise,
-            @PluginAttribute("advertiseURI") final String advertiseURI,
-            @PluginConfiguration final Configuration config) {
-            // @formatter:on
-        if (!bufferedIo && bufferSize > 0) {
-            LOGGER.warn("The bufferSize is set to {} but bufferedIO is not true: {}", bufferSize, bufferedIo);
-        }
-        if (name == null) {
-            LOGGER.error("No name provided for FileAppender");
-            return null;
-        }
-
-        if (fileName == null) {
-            LOGGER.error("No filename was provided for FileAppender with name "  + name);
-            return null;
-        }
-
-        if (filePattern == null) {
-            LOGGER.error("No filename pattern provided for FileAppender with name "  + name);
-            return null;
-        }
-
-        if (policy == null) {
-            LOGGER.error("A TriggeringPolicy must be provided");
-            return null;
-        }
-
-        if (strategy == null) {
-            strategy = DefaultRolloverStrategy.createStrategy(null, null, null,
-                    String.valueOf(Deflater.DEFAULT_COMPRESSION), null, true, config);
-        }
-
-        if (layout == null) {
-            layout = PatternLayout.createDefaultLayout();
-        }
-
-        final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, append,
-            bufferedIo, policy, strategy, advertiseURI, layout, bufferSize, immediateFlush);
-        if (manager == null) {
-            return null;
-        }
-
-        manager.initialize();
-
-        return new RollingFileAppender(name, layout, filter, manager, fileName, filePattern,
-                ignoreExceptions, immediateFlush, advertise ? config.getAdvertiser() : null);
+    @PluginBuilderFactory
+    public static <B extends Builder<B>> B newBuilder() {
+        return new Builder<B>().asBuilder();
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
index 4fdbf30..5f390f1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
@@ -32,6 +32,7 @@ import org.apache.logging.log4j.core.appender.FileManager;
 import org.apache.logging.log4j.core.appender.ManagerFactory;
 import org.apache.logging.log4j.core.appender.rolling.action.AbstractAction;
 import org.apache.logging.log4j.core.appender.rolling.action.Action;
+import org.apache.logging.log4j.core.util.Clock;
 import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.core.util.Log4jThread;
 
@@ -65,6 +66,7 @@ public class RollingFileManager extends FileManager {
                 writeHeader, ByteBuffer.wrap(new byte[Constants.ENCODER_BYTE_BUFFER_SIZE]));
     }
 
+    @Deprecated
     protected RollingFileManager(final String fileName, final String pattern, final OutputStream os,
             final boolean append, final long size, final long time, final TriggeringPolicy triggeringPolicy,
             final RolloverStrategy rolloverStrategy, final String advertiseURI,
@@ -78,6 +80,24 @@ public class RollingFileManager extends FileManager {
         this.patternProcessor.setPrevFileTime(time);
     }
 
+    /**
+     * @throws IOException 
+     * @since 2.7
+     */
+    protected RollingFileManager(final String fileName, final String pattern, final OutputStream os, final boolean append,
+            final boolean lazyCreate, final long size, final long time, final TriggeringPolicy triggeringPolicy,
+            final RolloverStrategy rolloverStrategy, final String advertiseURI,
+            final Layout<? extends Serializable> layout, final boolean writeHeader, final ByteBuffer buffer)
+            throws IOException {
+        super(fileName, os, append, false, lazyCreate, advertiseURI, layout, writeHeader, buffer);
+        this.size = size;
+        this.initialTime = time;
+        this.triggeringPolicy = triggeringPolicy;
+        this.rolloverStrategy = rolloverStrategy;
+        this.patternProcessor = new PatternProcessor(pattern);
+        this.patternProcessor.setPrevFileTime(time);
+    }
+
     public void initialize() {
         triggeringPolicy.initialize(this);
     }
@@ -93,15 +113,17 @@ public class RollingFileManager extends FileManager {
      * @param advertiseURI the URI to use when advertising the file
      * @param layout The Layout.
      * @param bufferSize buffer size to use if bufferedIO is true
+     * @param immediateFlush flush on every write or not
+     * @param lazyCreate true if you want to lazy-create the file (a.k.a. on-demand.)
      * @return A RollingFileManager.
      */
     public static RollingFileManager getFileManager(final String fileName, final String pattern, final boolean append,
             final boolean bufferedIO, final TriggeringPolicy policy, final RolloverStrategy strategy,
             final String advertiseURI, final Layout<? extends Serializable> layout, final int bufferSize,
-            final boolean immediateFlush) {
+            final boolean immediateFlush, final boolean lazyCreate) {
 
         return (RollingFileManager) getManager(fileName, new FactoryData(pattern, append,
-            bufferedIO, policy, strategy, advertiseURI, layout, bufferSize, immediateFlush), factory);
+            bufferedIO, policy, strategy, advertiseURI, layout, bufferSize, immediateFlush, lazyCreate), factory);
     }
 
     // override to make visible for unit tests
@@ -325,6 +347,7 @@ public class RollingFileManager extends FileManager {
         private final boolean bufferedIO;
         private final int bufferSize;
         private final boolean immediateFlush;
+        private final boolean lazyCreate;
         private final TriggeringPolicy policy;
         private final RolloverStrategy strategy;
         private final String advertiseURI;
@@ -339,10 +362,12 @@ public class RollingFileManager extends FileManager {
          * @param layout The Layout.
          * @param bufferSize the buffer size
          * @param immediateFlush flush on every write or not
+         * @param lazyCreate true if you want to lazy-create the file (a.k.a. on-demand.)
          */
         public FactoryData(final String pattern, final boolean append, final boolean bufferedIO,
                 final TriggeringPolicy policy, final RolloverStrategy strategy, final String advertiseURI,
-                final Layout<? extends Serializable> layout, final int bufferSize, final boolean immediateFlush) {
+                final Layout<? extends Serializable> layout, final int bufferSize, final boolean immediateFlush, 
+                final boolean lazyCreate) {
             this.pattern = pattern;
             this.append = append;
             this.bufferedIO = bufferedIO;
@@ -352,6 +377,7 @@ public class RollingFileManager extends FileManager {
             this.advertiseURI = advertiseURI;
             this.layout = layout;
             this.immediateFlush = immediateFlush;
+            this.lazyCreate = lazyCreate;
         }
 
         public TriggeringPolicy getTriggeringPolicy()
@@ -418,24 +444,24 @@ public class RollingFileManager extends FileManager {
             // LOG4J2-1140: check writeHeader before creating the file
             final boolean writeHeader = !data.append || !file.exists();
             try {
-                file.createNewFile();
+                final boolean created = data.lazyCreate ? false : file.createNewFile();
+                LOGGER.trace("New file '{}' created = {}", name, created);
             } catch (final IOException ioe) {
                 LOGGER.error("Unable to create file " + name, ioe);
                 return null;
             }
             final long size = data.append ? file.length() : 0;
 
-            OutputStream os;
             try {
-                os = new FileOutputStream(name, data.append);
                 final int actualSize = data.bufferedIO ? data.bufferSize : Constants.ENCODER_BYTE_BUFFER_SIZE;
                 final ByteBuffer buffer = ByteBuffer.wrap(new byte[actualSize]);
-
-                final long time = file.lastModified(); // LOG4J2-531 create file first so time has valid value
-                return new RollingFileManager(name, data.pattern, os, data.append, size, time, data.policy,
-                    data.strategy, data.advertiseURI, data.layout, writeHeader, buffer);
-            } catch (final FileNotFoundException ex) {
-                LOGGER.error("FileManager (" + name + ") " + ex, ex);
+                final OutputStream os = data.lazyCreate ? null : new FileOutputStream(name, data.append);
+                final long time = data.lazyCreate? System.currentTimeMillis() : file.lastModified(); // LOG4J2-531 create file first so time has valid value
+                
+                return new RollingFileManager(name, data.pattern, os, data.append, data.lazyCreate, size, time, data.policy,
+                        data.strategy, data.advertiseURI, data.layout, writeHeader, buffer);
+            } catch (final IOException ex) {
+                LOGGER.error("RollingFileManager (" + name + ") " + ex, ex);
             }
             return null;
         }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java
index eacf7c6..27f8e7e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java
@@ -32,7 +32,9 @@ import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.DefaultConfiguration;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.core.util.datetime.FastDateFormat;
+import org.apache.logging.log4j.junit.CleanFolders;
 import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
 
 /**
@@ -49,8 +51,8 @@ public class OnStartupTriggeringPolicyTest {
     private static final String TEST_DATA = "Hello world!";
     private static final FastDateFormat formatter = FastDateFormat.getInstance("MM-dd-yyyy");
 
-    // @Rule
-    // public CleanFolders rule = new CleanFolders("target/rollOnStartup");
+    @Rule
+    public CleanFolders rule = new CleanFolders("target/rollOnStartup");
 
     @Test
     public void testPolicy() throws Exception {
@@ -76,13 +78,13 @@ public class OnStartupTriggeringPolicyTest {
                 configuration);
         final OnStartupTriggeringPolicy policy = OnStartupTriggeringPolicy.createPolicy(1);
         final RollingFileManager manager = RollingFileManager.getFileManager(TARGET_FILE, TARGET_PATTERN, true, false,
-                policy, strategy, null, layout, 8192, true);
+                policy, strategy, null, layout, 8192, true, false);
         try {
             manager.initialize();
             String files = Arrays.toString(new File(TARGET_FOLDER).listFiles());
             assertTrue(target.toString() + ", files = " + files, Files.exists(target));
             assertEquals(target.toString(), 0, Files.size(target));
-            assertTrue(rolled.toString() + ", files = " + files, Files.exists(rolled));
+            assertTrue("Missing: " + rolled.toString() + ", files on disk = " + files, Files.exists(rolled));
             assertEquals(rolled.toString(), size, Files.size(rolled));
         } finally {
             manager.release();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
index 92e89b1..0560301 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
@@ -29,6 +29,9 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Collection;
 
@@ -37,8 +40,10 @@ import org.apache.commons.compress.compressors.CompressorInputStream;
 import org.apache.commons.compress.compressors.CompressorStreamFactory;
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.appender.RollingFileAppender;
 import org.apache.logging.log4j.core.util.Closer;
 import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -61,25 +66,34 @@ public class RollingAppenderSizeTest {
 
     private Logger logger;
 
-    @Parameterized.Parameters(name = "{0} \u2192 {1}")
+    private final boolean lazyCreate;
+
+    @Parameterized.Parameters(name = "{0} \u2192 {1} (lazyCreate = {2})")
     public static Collection<Object[]> data() {
         return Arrays.asList(new Object[][] { //
                 // @formatter:off
-                {"log4j-rolling-gz.xml", ".gz"}, //
-                {"log4j-rolling-zip.xml", ".zip"}, //
+               {"log4j-rolling-gz-lazy.xml", ".gz", true}, //
+               {"log4j-rolling-gz.xml", ".gz", false}, //
+               {"log4j-rolling-zip-lazy.xml", ".zip", true}, //
+               {"log4j-rolling-zip.xml", ".zip", false}, //
                 // Apache Commons Compress
-                {"log4j-rolling-bzip2.xml", ".bz2"}, //
-                {"log4j-rolling-deflate.xml", ".deflate"}, //
-                {"log4j-rolling-pack200.xml", ".pack200"}, //
-                {"log4j-rolling-xz.xml", ".xz"}, //
+               {"log4j-rolling-bzip2-lazy.xml", ".bz2", true}, //
+               {"log4j-rolling-bzip2.xml", ".bz2", false}, //
+               {"log4j-rolling-deflate-lazy.xml", ".deflate", true}, //
+               {"log4j-rolling-deflate.xml", ".deflate", false}, //
+               {"log4j-rolling-pack200-lazy.xml", ".pack200", true}, //
+               {"log4j-rolling-pack200.xml", ".pack200", false}, //
+               {"log4j-rolling-xz-lazy.xml", ".xz", true}, //
+               {"log4j-rolling-xz.xml", ".xz", false}, //
                 });
                 // @formatter:on
     }
 
     private LoggerContextRule loggerContextRule;
 
-    public RollingAppenderSizeTest(final String configFile, final String fileExtension) {
+    public RollingAppenderSizeTest(final String configFile, final String fileExtension, final boolean lazyCreate) {
         this.fileExtension = fileExtension;
+        this.lazyCreate = lazyCreate;
         this.loggerContextRule = new LoggerContextRule(configFile);
         this.chain = loggerContextRule.withCleanFoldersRule(DIR);
     }
@@ -90,7 +104,20 @@ public class RollingAppenderSizeTest {
     }
 
     @Test
+    public void testIsLazyCreate() {
+        final RollingFileAppender rfAppender = loggerContextRule.getRequiredAppender("RollingFile",
+                RollingFileAppender.class);
+        final RollingFileManager manager = rfAppender.getManager();
+        Assert.assertNotNull(manager);
+        Assert.assertEquals(lazyCreate, manager.isLazyCreate());
+    }
+
+    @Test
     public void testAppender() throws Exception {
+        final Path path = Paths.get(DIR, "rollingtest.log");
+        if (Files.exists(path) && lazyCreate) {
+            Assert.fail(String.format("Unexpected file: %s (%s bytes)", path, Files.getAttribute(path, "size")));
+        }
         for (int i = 0; i < 100; ++i) {
             logger.debug("This is test message number " + i);
         }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
index d22fc6a..b484567 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.RollingFileAppender;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class RollingFileAppenderAccessTest {
@@ -32,19 +33,26 @@ public class RollingFileAppenderAccessTest {
      * @throws IOException
      */
     @Test
-    public void testAccessManagerWithStrings() throws IOException {
-        final LoggerContext ctx = LoggerContext.getContext(false);
-        final Configuration config = ctx.getConfiguration();
-        final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp");
-        file.deleteOnExit();
-        final RollingFileAppender appender = RollingFileAppender.createAppender(file.getCanonicalPath(), "FilePattern",
-                null, "Name", null, null, null, OnStartupTriggeringPolicy.createPolicy(1), null, null, null, null, null,
-                null, config);
-        final RollingFileManager manager = appender.getManager();
-        // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their
-        // access.
-        manager.getRolloverStrategy();
-        manager.getTriggeringPolicy();
+    public void testAccessManagerWithBuilder() throws IOException {
+        try (final LoggerContext ctx = LoggerContext.getContext(false)) {
+            final Configuration config = ctx.getConfiguration();
+            final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp");
+            file.deleteOnExit();
+            // @formatter:off
+            final RollingFileAppender appender = RollingFileAppender.newBuilder()
+                    .withFileName(file.getCanonicalPath())
+                    .withFilePattern("FilePattern")
+                    .withName("Name")
+                    .withPolicy(OnStartupTriggeringPolicy.createPolicy(1))
+                    .withConfig(config)
+                    .build();
+            // @formatter:on
+            final RollingFileManager manager = appender.getManager();
+            // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their
+            // access.
+            Assert.assertNotNull(manager.getRolloverStrategy());
+            Assert.assertNotNull(manager.getTriggeringPolicy());
+        }
     }
 
     /**
@@ -53,18 +61,19 @@ public class RollingFileAppenderAccessTest {
      * @throws IOException
      */
     @Test
-    public void testAccessManagerWithPrimitives() throws IOException {
-        final LoggerContext ctx = LoggerContext.getContext(false);
-        final Configuration config = ctx.getConfiguration();
-        final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp");
-        file.deleteOnExit();
-        final RollingFileAppender appender = RollingFileAppender.createAppender(file.getCanonicalPath(), "FilePattern",
-                true, "Name", true, 8192, true, OnStartupTriggeringPolicy.createPolicy(1), null, null, null, true, false,
-                null, config);
-        final RollingFileManager manager = appender.getManager();
-        // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their
-        // access.
-        manager.getRolloverStrategy();
-        manager.getTriggeringPolicy();
+    public void testAccessManagerWithStrings() throws IOException {
+        try (final LoggerContext ctx = LoggerContext.getContext(false)) {
+            final Configuration config = ctx.getConfiguration();
+            final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp");
+            file.deleteOnExit();
+            final RollingFileAppender appender = RollingFileAppender.createAppender(file.getCanonicalPath(),
+                    "FilePattern", null, "Name", null, null, null, OnStartupTriggeringPolicy.createPolicy(1), null,
+                    null, null, null, null, null, config);
+            final RollingFileManager manager = appender.getManager();
+            // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their
+            // access.
+            Assert.assertNotNull(manager.getRolloverStrategy());
+            Assert.assertNotNull(manager.getTriggeringPolicy());
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml
new file mode 100644
index 0000000..ce16320
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml
@@ -0,0 +1,59 @@
+<?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="OFF" name="XMLConfigTest">
+  <Properties>
+    <Property name="filename">target/rolling1/rollingtest.log</Property>
+  </Properties>
+  <ThresholdFilter level="debug"/>
+
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <RollingFile name="RollingFile" fileName="${filename}"
+                 filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.7z"
+                 lazyCreate="true">
+      <PatternLayout>
+        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <SizeBasedTriggeringPolicy size="500" />
+    </RollingFile>
+    <List name="List">
+      <ThresholdFilter level="error"/>
+    </List>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+      <ThreadContextMapFilter>
+        <KeyValuePair key="test" value="123"/>
+      </ThreadContextMapFilter>
+      <AppenderRef ref="STDOUT"/>
+    </Logger>>
+
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>>
+
+    <Root level="error">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml
new file mode 100644
index 0000000..6697293
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml
@@ -0,0 +1,60 @@
+<?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="OFF" name="XMLConfigTest">
+  <Properties>
+    <Property name="filename">target/rolling1/rollingtest.log</Property>
+  </Properties>
+  <ThresholdFilter level="debug"/>
+
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <RollingFile name="RollingFile" fileName="${filename}"
+                 filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.bz2"
+                 lazyCreate="true">
+      <PatternLayout>
+        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <SizeBasedTriggeringPolicy size="500" />
+      <DefaultRolloverStrategy compressionLevel="9" />
+    </RollingFile>
+    <List name="List">
+      <ThresholdFilter level="error"/>
+    </List>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+      <ThreadContextMapFilter>
+        <KeyValuePair key="test" value="123"/>
+      </ThreadContextMapFilter>
+      <AppenderRef ref="STDOUT"/>
+    </Logger>>
+
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>>
+
+    <Root level="error">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml
new file mode 100644
index 0000000..d4561f7
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml
@@ -0,0 +1,60 @@
+<?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="OFF" name="XMLConfigTest">
+  <Properties>
+    <Property name="filename">target/rolling1/rollingtest.log</Property>
+  </Properties>
+  <ThresholdFilter level="debug"/>
+
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <RollingFile name="RollingFile" fileName="${filename}"
+                 filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.deflate"
+                 lazyCreate="true">
+      <PatternLayout>
+        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <SizeBasedTriggeringPolicy size="500" />
+      <DefaultRolloverStrategy compressionLevel="9" />
+    </RollingFile>
+    <List name="List">
+      <ThresholdFilter level="error"/>
+    </List>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+      <ThreadContextMapFilter>
+        <KeyValuePair key="test" value="123"/>
+      </ThreadContextMapFilter>
+      <AppenderRef ref="STDOUT"/>
+    </Logger>>
+
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>>
+
+    <Root level="error">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml
new file mode 100644
index 0000000..f9bfd90
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml
@@ -0,0 +1,59 @@
+<?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="OFF" name="XMLConfigTest">
+  <Properties>
+    <Property name="filename">target/rolling1/rollingtest.log</Property>
+  </Properties>
+  <ThresholdFilter level="debug"/>
+
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <RollingFile name="RollingFile" fileName="${filename}"
+                 filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.gz"
+                 lazyCreate="true">
+      <PatternLayout>
+        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <SizeBasedTriggeringPolicy size="500" />
+    </RollingFile>
+    <List name="List">
+      <ThresholdFilter level="error"/>
+    </List>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+      <ThreadContextMapFilter>
+        <KeyValuePair key="test" value="123"/>
+      </ThreadContextMapFilter>
+      <AppenderRef ref="STDOUT"/>
+    </Logger>>
+
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>>
+
+    <Root level="error">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml
new file mode 100644
index 0000000..7355e61
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml
@@ -0,0 +1,60 @@
+<?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="OFF" name="XMLConfigTest">
+  <Properties>
+    <Property name="filename">target/rolling1/rollingtest.log</Property>
+  </Properties>
+  <ThresholdFilter level="debug"/>
+
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <RollingFile name="RollingFile" fileName="${filename}"
+                 filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.pack200"
+                 lazyCreate="true">
+      <PatternLayout>
+        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <SizeBasedTriggeringPolicy size="500" />
+      <DefaultRolloverStrategy compressionLevel="9" />
+    </RollingFile>
+    <List name="List">
+      <ThresholdFilter level="error"/>
+    </List>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+      <ThreadContextMapFilter>
+        <KeyValuePair key="test" value="123"/>
+      </ThreadContextMapFilter>
+      <AppenderRef ref="STDOUT"/>
+    </Logger>>
+
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>>
+
+    <Root level="error">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml
new file mode 100644
index 0000000..02aa528
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml
@@ -0,0 +1,60 @@
+<?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="OFF" name="XMLConfigTest">
+  <Properties>
+    <Property name="filename">target/rolling1/rollingtest.log</Property>
+  </Properties>
+  <ThresholdFilter level="debug"/>
+
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <RollingFile name="RollingFile" fileName="${filename}"
+                 filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.xz"
+                 lazyCreate="true">
+      <PatternLayout>
+        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <SizeBasedTriggeringPolicy size="500" />
+      <DefaultRolloverStrategy compressionLevel="9" />
+    </RollingFile>
+    <List name="List">
+      <ThresholdFilter level="error"/>
+    </List>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+      <ThreadContextMapFilter>
+        <KeyValuePair key="test" value="123"/>
+      </ThreadContextMapFilter>
+      <AppenderRef ref="STDOUT"/>
+    </Logger>>
+
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>>
+
+    <Root level="error">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml
new file mode 100644
index 0000000..2641d7f
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml
@@ -0,0 +1,60 @@
+<?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="OFF" name="XMLConfigTest">
+  <Properties>
+    <Property name="filename">target/rolling1/rollingtest.log</Property>
+  </Properties>
+  <ThresholdFilter level="debug"/>
+
+  <Appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <RollingFile name="RollingFile" fileName="${filename}"
+                 filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.zip"
+                 lazyCreate="true">
+      <PatternLayout>
+        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <SizeBasedTriggeringPolicy size="500" />
+      <DefaultRolloverStrategy compressionLevel="9" />
+    </RollingFile>
+    <List name="List">
+      <ThresholdFilter level="error"/>
+    </List>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+      <ThreadContextMapFilter>
+        <KeyValuePair key="test" value="123"/>
+      </ThreadContextMapFilter>
+      <AppenderRef ref="STDOUT"/>
+    </Logger>>
+
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>>
+
+    <Root level="error">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a82794f0/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 675a24a..36bb642 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,7 +67,10 @@
         Properties declared in configuration can now have their value either in the element body or in an attribute named "value".
       </action>
       <action issue="LOG4J2-1501" dev="ggregory" type="add" due-to="Gary Gregory">
-        FileAppender should be able to create files lazily.
+        FileAppender should be able to create files on-demand.
+      </action>
+      <action issue="LOG4J2-1504" dev="ggregory" type="add" due-to="Gary Gregory">
+        RollingFileAppender should be able to create files on-demand.
       </action>
       <action issue="LOG4J2-1471" dev="ggregory" type="add" due-to="Gary Gregory">
         [PatternLayout] Add an ANSI option to %xThrowable.


[6/8] logging-log4j2 git commit: Don't need ()s.

Posted by rp...@apache.org.
Don't need ()s.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1f232974
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1f232974
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1f232974

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 1f232974db103b64a3b6741fe8f8bea18a899ae9
Parents: 4e5ef98
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Aug 19 18:13:16 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Aug 19 18:13:16 2016 -0700

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/async/DaemonThreadFactory.java  | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1f232974/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
index f853b32..90a15e0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
@@ -33,8 +33,7 @@ public class DaemonThreadFactory implements ThreadFactory {
     public DaemonThreadFactory(final String threadNamePrefix) {
         this.threadNamePrefix = threadNamePrefix;
         final SecurityManager securityManager = System.getSecurityManager();
-        group = (securityManager != null) ? securityManager.getThreadGroup()
-                : Thread.currentThread().getThreadGroup();
+        group = securityManager != null ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup();
     }
 
     @Override


[3/8] logging-log4j2 git commit: LOG4J2-1527 Prevent NPE in RingBufferLogEvent.getFormattedMessage() when used in web applications.

Posted by rp...@apache.org.
LOG4J2-1527 Prevent NPE in RingBufferLogEvent.getFormattedMessage() when used in web applications.

This closes #39 (https://github.com/apache/logging-log4j2/pull/39 )


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/147f78c4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/147f78c4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/147f78c4

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 147f78c45e181d78778a710d24510c9b03d97bc7
Parents: 6a23301
Author: rpopma <rp...@apache.org>
Authored: Sat Aug 20 09:44:20 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Aug 20 09:44:20 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/async/RingBufferLogEvent.java      |  4 +++-
 .../log4j/core/async/RingBufferLogEventTest.java  | 18 ++++++++++++++----
 src/changes/changes.xml                           |  4 ++++
 3 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/147f78c4/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index c4de9d4..76b00a1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -210,7 +210,9 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
      */
     @Override
     public String getFormattedMessage() {
-        return messageText.toString();
+        return messageText != null // LOG4J2-1527: may be null in web apps
+                ? messageText.toString() // note: please keep below "redundant" braces for readability
+                : (message == null ? null : message.getFormattedMessage());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/147f78c4/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
index ec3a874..5c7f467 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
@@ -121,11 +121,11 @@ public class RingBufferLogEventTest {
         final long nanoTime = 1;
         evt.setValues(null, loggerName, marker, fqcn, level, data, t, map,
                 contextStack, -1, threadName, -1, location, currentTimeMillis, nanoTime);
-        
+
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
         final ObjectOutputStream out = new ObjectOutputStream(baos);
         out.writeObject(evt);
-        
+
         final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
         final RingBufferLogEvent other = (RingBufferLogEvent) in.readObject();
         assertEquals(loggerName, other.getLoggerName());
@@ -141,7 +141,7 @@ public class RingBufferLogEventTest {
         assertEquals(location, other.getSource());
         assertEquals(currentTimeMillis, other.getTimeMillis());
     }
-    
+
     @Test
     public void testCreateMementoReturnsCopy() {
         final RingBufferLogEvent evt = new RingBufferLogEvent();
@@ -160,7 +160,7 @@ public class RingBufferLogEventTest {
         final long nanoTime = 1;
         evt.setValues(null, loggerName, marker, fqcn, level, data, t, map,
                 contextStack, -1, threadName, -1, location, currentTimeMillis, nanoTime);
-        
+
         final LogEvent actual = evt.createMemento();
         assertEquals(evt.getLoggerName(), actual.getLoggerName());
         assertEquals(evt.getMarker(), actual.getMarker());
@@ -175,4 +175,14 @@ public class RingBufferLogEventTest {
         assertEquals(evt.getSource(), actual.getSource());
         assertEquals(evt.getThrownProxy(), actual.getThrownProxy());
     }
+
+    @Test
+    public void testMessageTextNeverThrowsNpe() {
+        final RingBufferLogEvent evt = new RingBufferLogEvent();
+        try {
+            evt.getFormattedMessage();
+        } catch (NullPointerException e) {
+            fail("the messageText field was not set");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/147f78c4/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index be283c7..1ea373c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,10 @@
   </properties>
   <body>
     <release version="2.7" date="2016-MM-DD" description="GA Release 2.7">
+
+      <action issue="LOG4J2-1527" dev="rpopma" type="fix" due-to="Jose Leon">
+        Prevent NPE in RingBufferLogEvent.getFormattedMessage() when used in web applications.
+      </action>
       <action issue="LOG4J2-905" dev="ggregory" type="fix" due-to="Gary Gregory, Moritz L�ser">
         Ability to disable (date) lookup completely, compatibility issues with other libraries like Camel.
       </action>


[2/8] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master'

Posted by rp...@apache.org.
Merge remote-tracking branch 'origin/master'

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/93f55f37
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/93f55f37
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/93f55f37

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 93f55f378d72e806ac0672f88d24a908097d654b
Parents: a82794f 6a23301
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Aug 19 17:27:38 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Aug 19 17:27:38 2016 -0700

----------------------------------------------------------------------
 .../org/apache/logging/log4j/ThreadContext.java | 55 +++++++++++---------
 .../log4j/spi/DefaultThreadContextMap.java      |  6 +--
 .../logging/log4j/spi/ThreadContextMap.java     | 13 +----
 .../logging/log4j/spi/ThreadContextMap2.java    | 40 ++++++++++++++
 .../org/apache/logging/slf4j/MDCContextMap.java |  7 +--
 src/changes/changes.xml                         |  4 +-
 6 files changed, 81 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/93f55f37/src/changes/changes.xml
----------------------------------------------------------------------


[5/8] logging-log4j2 git commit: Replace "lazyCreate" with "createOnDemand".

Posted by rp...@apache.org.
Replace "lazyCreate" with "createOnDemand".

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4e5ef989
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4e5ef989
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4e5ef989

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 4e5ef989c3126276f752435e91c6f7ea5ad0a52d
Parents: b3d6a39
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Aug 19 18:10:27 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Aug 19 18:10:27 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/appender/FileAppender.java       | 12 ++---
 .../log4j/core/appender/FileManager.java        | 32 ++++++-------
 .../core/appender/OutputStreamManager.java      |  4 +-
 .../core/appender/RollingFileAppender.java      | 14 +++---
 .../appender/rolling/RollingFileManager.java    | 26 +++++------
 .../log4j/core/appender/FileAppenderTest.java   | 48 ++++++++++----------
 .../rolling/RollingAppenderSizeTest.java        | 38 ++++++++--------
 .../test/resources/log4j-rolling-7z-lazy.xml    |  2 +-
 .../test/resources/log4j-rolling-bzip2-lazy.xml |  2 +-
 .../resources/log4j-rolling-deflate-lazy.xml    |  2 +-
 .../test/resources/log4j-rolling-gz-lazy.xml    |  2 +-
 .../resources/log4j-rolling-pack200-lazy.xml    |  2 +-
 .../test/resources/log4j-rolling-xz-lazy.xml    |  2 +-
 .../test/resources/log4j-rolling-zip-lazy.xml   |  2 +-
 14 files changed, 94 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
index e93e05f..5c8eff4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
@@ -70,7 +70,7 @@ public final class FileAppender extends AbstractOutputStreamAppender<FileManager
         private String advertiseUri;
 
         @PluginBuilderAttribute
-        private boolean lazyCreate;
+        private boolean createOnDemand;
 
         @PluginConfiguration
         private Configuration config;
@@ -86,7 +86,7 @@ public final class FileAppender extends AbstractOutputStreamAppender<FileManager
             }
             Layout<? extends Serializable> layout = getOrCreateLayout();
 
-            final FileManager manager = FileManager.getFileManager(fileName, append, locking, bufferedIo, lazyCreate,
+            final FileManager manager = FileManager.getFileManager(fileName, append, locking, bufferedIo, createOnDemand,
                     advertiseUri, layout, bufferSize, isImmediateFlush());
             if (manager == null) {
                 return null;
@@ -124,8 +124,8 @@ public final class FileAppender extends AbstractOutputStreamAppender<FileManager
             return bufferedIo;
         }
 
-        public boolean isLazyCreate() {
-            return lazyCreate;
+        public boolean isCreateOnDemand() {
+            return createOnDemand;
         }
 
         public boolean isLocking() {
@@ -167,8 +167,8 @@ public final class FileAppender extends AbstractOutputStreamAppender<FileManager
             return asBuilder();
         }
 
-        public B withLazyCreate(final boolean lazyCreate) {
-            this.lazyCreate = lazyCreate;
+        public B withCreateOnDemand(final boolean createOnDemand) {
+            this.createOnDemand = createOnDemand;
             return asBuilder();
         }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
index b8a559a..2b9024b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
@@ -40,7 +40,7 @@ public class FileManager extends OutputStreamManager {
     private static final FileManagerFactory FACTORY = new FileManagerFactory();
 
     private final boolean isAppend;
-    private final boolean isLazyCreate;
+    private final boolean createOnDemand;
     private final boolean isLocking;
     private final String advertiseURI;
     private final int bufferSize;
@@ -65,7 +65,7 @@ public class FileManager extends OutputStreamManager {
             final ByteBuffer buffer) {
         super(os, fileName, layout, writeHeader, buffer);
         this.isAppend = append;
-        this.isLazyCreate = false;
+        this.createOnDemand = false;
         this.isLocking = locking;
         this.advertiseURI = advertiseURI;
         this.bufferSize = buffer.capacity();
@@ -75,12 +75,12 @@ public class FileManager extends OutputStreamManager {
      * @throws IOException 
      * @since 2.7 
      */
-    protected FileManager(final String fileName, final OutputStream os, final boolean append, final boolean locking, final boolean lazyCreate,
+    protected FileManager(final String fileName, final OutputStream os, final boolean append, final boolean locking, final boolean createOnDemand,
             final String advertiseURI, final Layout<? extends Serializable> layout, final boolean writeHeader,
             final ByteBuffer buffer) throws IOException {
-        super(os, fileName, lazyCreate, layout, writeHeader, buffer);
+        super(os, fileName, createOnDemand, layout, writeHeader, buffer);
         this.isAppend = append;
-        this.isLazyCreate = lazyCreate;
+        this.createOnDemand = createOnDemand;
         this.isLocking = locking;
         this.advertiseURI = advertiseURI;
         this.bufferSize = buffer.capacity();
@@ -92,7 +92,7 @@ public class FileManager extends OutputStreamManager {
      * @param append true if the file should be appended to, false if it should be overwritten.
      * @param locking true if the file should be locked while writing, false otherwise.
      * @param bufferedIo true if the contents should be buffered as they are written.
-     * @param lazyCreate true if you want to lazy-create the file (a.k.a. on-demand.)
+     * @param createOnDemand true if you want to lazy-create the file (a.k.a. on-demand.)
      * @param advertiseUri the URI to use when advertising the file
      * @param layout The layout
      * @param bufferSize buffer size for buffered IO
@@ -100,14 +100,14 @@ public class FileManager extends OutputStreamManager {
      * @return A FileManager for the File.
      */
     public static FileManager getFileManager(final String fileName, final boolean append, boolean locking,
-            final boolean bufferedIo, final boolean lazyCreate, final String advertiseUri,
+            final boolean bufferedIo, final boolean createOnDemand, final String advertiseUri,
             final Layout<? extends Serializable> layout, final int bufferSize, final boolean immediateFlush) {
 
         if (locking && bufferedIo) {
             locking = false;
         }
         return (FileManager) getManager(fileName,
-                new FactoryData(append, locking, bufferedIo, bufferSize, immediateFlush, lazyCreate, advertiseUri, layout),
+                new FactoryData(append, locking, bufferedIo, bufferSize, immediateFlush, createOnDemand, advertiseUri, layout),
                 FACTORY);
     }
 
@@ -162,8 +162,8 @@ public class FileManager extends OutputStreamManager {
      * Returns the lazy-create.
      * @return true if the file will be lazy-created.
      */
-    public boolean isLazyCreate() {
-        return isLazyCreate;
+    public boolean isCreateOnDemand() {
+        return createOnDemand;
     }
 
     /**
@@ -204,7 +204,7 @@ public class FileManager extends OutputStreamManager {
         private final boolean bufferedIO;
         private final int bufferSize;
         private final boolean immediateFlush;
-        private final boolean lazyCreate;
+        private final boolean createOnDemand;
         private final String advertiseURI;
         private final Layout<? extends Serializable> layout;
 
@@ -215,19 +215,19 @@ public class FileManager extends OutputStreamManager {
          * @param bufferedIO Buffering flag.
          * @param bufferSize Buffer size.
          * @param immediateFlush flush on every write or not
-         * @param lazyCreate if you want to lazy-create the file (a.k.a. on-demand.)
+         * @param createOnDemand if you want to lazy-create the file (a.k.a. on-demand.)
          * @param advertiseURI the URI to use when advertising the file
          * @param layout The layout
          */
         public FactoryData(final boolean append, final boolean locking, final boolean bufferedIO, final int bufferSize,
-                final boolean immediateFlush, final boolean lazyCreate, final String advertiseURI,
+                final boolean immediateFlush, final boolean createOnDemand, final String advertiseURI,
                 final Layout<? extends Serializable> layout) {
             this.append = append;
             this.locking = locking;
             this.bufferedIO = bufferedIO;
             this.bufferSize = bufferSize;
             this.immediateFlush = immediateFlush;
-            this.lazyCreate = lazyCreate;
+            this.createOnDemand = createOnDemand;
             this.advertiseURI = advertiseURI;
             this.layout = layout;
         }
@@ -256,8 +256,8 @@ public class FileManager extends OutputStreamManager {
             try {
                 final int actualSize = data.bufferedIO ? data.bufferSize : Constants.ENCODER_BYTE_BUFFER_SIZE;
                 final ByteBuffer buffer = ByteBuffer.wrap(new byte[actualSize]);
-                final FileOutputStream fos = data.lazyCreate ? null : new FileOutputStream(file, data.append);
-                return new FileManager(name, fos, data.append, data.locking, data.lazyCreate, data.advertiseURI, data.layout,
+                final FileOutputStream fos = data.createOnDemand ? null : new FileOutputStream(file, data.append);
+                return new FileManager(name, fos, data.append, data.locking, data.createOnDemand, data.advertiseURI, data.layout,
                         writeHeader, buffer);
             } catch (final IOException ex) {
                 LOGGER.error("FileManager (" + name + ") " + ex, ex);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
index d895dd5..e5960ee 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
@@ -69,11 +69,11 @@ public class OutputStreamManager extends AbstractManager implements ByteBufferDe
      * @throws IOException 
      * @since 2.7
      */
-    protected OutputStreamManager(OutputStream os, final String streamName, final boolean lazyCreate,
+    protected OutputStreamManager(OutputStream os, final String streamName, final boolean createOnDemand,
             final Layout<? extends Serializable> layout, final boolean writeHeader, final ByteBuffer byteBuffer)
             throws IOException {
         super(streamName);
-        if (lazyCreate && os != null) {
+        if (createOnDemand && os != null) {
             LOGGER.error(
                     "Invalid OutputStreamManager configuration for '{}': You cannot both set the OutputStream and request on-demand.",
                     streamName);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
index dc830e3..fcef0d6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
@@ -91,7 +91,7 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll
         private String advertiseUri;
 
         @PluginBuilderAttribute
-        private boolean lazyCreate;
+        private boolean createOnDemand;
 
         @PluginConfiguration
         private Configuration config;
@@ -136,7 +136,7 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll
 
             final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, append,
                     bufferedIo, policy, strategy, advertiseUri, getLayout(), bufferSize, isImmediateFlush(),
-                    lazyCreate);
+                    createOnDemand);
             if (manager == null) {
                 return null;
             }
@@ -175,8 +175,8 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll
             return bufferedIo;
         }
 
-        public boolean isLazyCreate() {
-            return lazyCreate;
+        public boolean isCreateOnDemand() {
+            return createOnDemand;
         }
 
         public boolean isLocking() {
@@ -218,8 +218,8 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll
             return asBuilder();
         }
 
-        public B withLazyCreate(final boolean lazyCreate) {
-            this.lazyCreate = lazyCreate;
+        public B withCreateOnDemand(final boolean createOnDemand) {
+            this.createOnDemand = createOnDemand;
             return asBuilder();
         }
 
@@ -379,7 +379,7 @@ public final class RollingFileAppender extends AbstractOutputStreamAppender<Roll
                 .withIgnoreExceptions(Booleans.parseBoolean(ignore, true))
                 .withImmediateFlush(Booleans.parseBoolean(immediateFlush, true))
                 .withLayout(layout)
-                .withLazyCreate(false)
+                .withCreateOnDemand(false)
                 .withLocking(false)
                 .withName(name)
                 .withPolicy(policy)

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
index 5f390f1..3c6739f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
@@ -85,11 +85,11 @@ public class RollingFileManager extends FileManager {
      * @since 2.7
      */
     protected RollingFileManager(final String fileName, final String pattern, final OutputStream os, final boolean append,
-            final boolean lazyCreate, final long size, final long time, final TriggeringPolicy triggeringPolicy,
+            final boolean createOnDemand, final long size, final long time, final TriggeringPolicy triggeringPolicy,
             final RolloverStrategy rolloverStrategy, final String advertiseURI,
             final Layout<? extends Serializable> layout, final boolean writeHeader, final ByteBuffer buffer)
             throws IOException {
-        super(fileName, os, append, false, lazyCreate, advertiseURI, layout, writeHeader, buffer);
+        super(fileName, os, append, false, createOnDemand, advertiseURI, layout, writeHeader, buffer);
         this.size = size;
         this.initialTime = time;
         this.triggeringPolicy = triggeringPolicy;
@@ -114,16 +114,16 @@ public class RollingFileManager extends FileManager {
      * @param layout The Layout.
      * @param bufferSize buffer size to use if bufferedIO is true
      * @param immediateFlush flush on every write or not
-     * @param lazyCreate true if you want to lazy-create the file (a.k.a. on-demand.)
+     * @param createOnDemand true if you want to lazy-create the file (a.k.a. on-demand.)
      * @return A RollingFileManager.
      */
     public static RollingFileManager getFileManager(final String fileName, final String pattern, final boolean append,
             final boolean bufferedIO, final TriggeringPolicy policy, final RolloverStrategy strategy,
             final String advertiseURI, final Layout<? extends Serializable> layout, final int bufferSize,
-            final boolean immediateFlush, final boolean lazyCreate) {
+            final boolean immediateFlush, final boolean createOnDemand) {
 
         return (RollingFileManager) getManager(fileName, new FactoryData(pattern, append,
-            bufferedIO, policy, strategy, advertiseURI, layout, bufferSize, immediateFlush, lazyCreate), factory);
+            bufferedIO, policy, strategy, advertiseURI, layout, bufferSize, immediateFlush, createOnDemand), factory);
     }
 
     // override to make visible for unit tests
@@ -347,7 +347,7 @@ public class RollingFileManager extends FileManager {
         private final boolean bufferedIO;
         private final int bufferSize;
         private final boolean immediateFlush;
-        private final boolean lazyCreate;
+        private final boolean createOnDemand;
         private final TriggeringPolicy policy;
         private final RolloverStrategy strategy;
         private final String advertiseURI;
@@ -362,12 +362,12 @@ public class RollingFileManager extends FileManager {
          * @param layout The Layout.
          * @param bufferSize the buffer size
          * @param immediateFlush flush on every write or not
-         * @param lazyCreate true if you want to lazy-create the file (a.k.a. on-demand.)
+         * @param createOnDemand true if you want to lazy-create the file (a.k.a. on-demand.)
          */
         public FactoryData(final String pattern, final boolean append, final boolean bufferedIO,
                 final TriggeringPolicy policy, final RolloverStrategy strategy, final String advertiseURI,
                 final Layout<? extends Serializable> layout, final int bufferSize, final boolean immediateFlush, 
-                final boolean lazyCreate) {
+                final boolean createOnDemand) {
             this.pattern = pattern;
             this.append = append;
             this.bufferedIO = bufferedIO;
@@ -377,7 +377,7 @@ public class RollingFileManager extends FileManager {
             this.advertiseURI = advertiseURI;
             this.layout = layout;
             this.immediateFlush = immediateFlush;
-            this.lazyCreate = lazyCreate;
+            this.createOnDemand = createOnDemand;
         }
 
         public TriggeringPolicy getTriggeringPolicy()
@@ -444,7 +444,7 @@ public class RollingFileManager extends FileManager {
             // LOG4J2-1140: check writeHeader before creating the file
             final boolean writeHeader = !data.append || !file.exists();
             try {
-                final boolean created = data.lazyCreate ? false : file.createNewFile();
+                final boolean created = data.createOnDemand ? false : file.createNewFile();
                 LOGGER.trace("New file '{}' created = {}", name, created);
             } catch (final IOException ioe) {
                 LOGGER.error("Unable to create file " + name, ioe);
@@ -455,10 +455,10 @@ public class RollingFileManager extends FileManager {
             try {
                 final int actualSize = data.bufferedIO ? data.bufferSize : Constants.ENCODER_BYTE_BUFFER_SIZE;
                 final ByteBuffer buffer = ByteBuffer.wrap(new byte[actualSize]);
-                final OutputStream os = data.lazyCreate ? null : new FileOutputStream(name, data.append);
-                final long time = data.lazyCreate? System.currentTimeMillis() : file.lastModified(); // LOG4J2-531 create file first so time has valid value
+                final OutputStream os = data.createOnDemand ? null : new FileOutputStream(name, data.append);
+                final long time = data.createOnDemand? System.currentTimeMillis() : file.lastModified(); // LOG4J2-531 create file first so time has valid value
                 
-                return new RollingFileManager(name, data.pattern, os, data.append, data.lazyCreate, size, time, data.policy,
+                return new RollingFileManager(name, data.pattern, os, data.append, data.createOnDemand, size, time, data.policy,
                         data.strategy, data.advertiseURI, data.layout, writeHeader, buffer);
             } catch (final IOException ex) {
                 LOGGER.error("RollingFileManager (" + name + ") " + ex, ex);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
index feb9f11..0ffb9a0 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
@@ -55,7 +55,7 @@ import org.junit.runners.Parameterized.Parameters;
 @RunWith(Parameterized.class)
 public class FileAppenderTest {
 
-    @Parameters(name = "lazyCreate = {0}")
+    @Parameters(name = "createOnDemand = {0}")
     public static Boolean[] getParameters() {
         return new Boolean[] { false, true };
     }
@@ -64,12 +64,12 @@ public class FileAppenderTest {
     private static final Path PATH = Paths.get(FILE_NAME);
     private static final int THREADS = 2;
 
-    public FileAppenderTest(boolean lazyCreate) {
+    public FileAppenderTest(boolean createOnDemand) {
         super();
-        this.lazyCreate = lazyCreate;
+        this.createOnDemand = createOnDemand;
     }
 
-    private final boolean lazyCreate;
+    private final boolean createOnDemand;
     private final int threadCount = THREADS;
 
     @Rule
@@ -83,7 +83,7 @@ public class FileAppenderTest {
     @Test
     public void testAppender() throws Exception {
         final int logEventCount = 1;
-        writer(false, logEventCount, "test", lazyCreate, false);
+        writer(false, logEventCount, "test", createOnDemand, false);
         verifyFile(logEventCount);
     }
 
@@ -99,18 +99,18 @@ public class FileAppenderTest {
             .withBufferedIo(false)
             .withBufferSize(1)
             .withLayout(layout)
-            .withLazyCreate(lazyCreate)
+            .withCreateOnDemand(createOnDemand)
             .build();
         // @formatter:on
-        Assert.assertEquals(lazyCreate, appender.getManager().isLazyCreate());
+        Assert.assertEquals(createOnDemand, appender.getManager().isCreateOnDemand());
         try {
-            Assert.assertNotEquals(lazyCreate, Files.exists(PATH));
+            Assert.assertNotEquals(createOnDemand, Files.exists(PATH));
             appender.start();
-            Assert.assertNotEquals(lazyCreate, Files.exists(PATH));
+            Assert.assertNotEquals(createOnDemand, Files.exists(PATH));
         } finally {
             appender.stop();
         }
-        Assert.assertNotEquals(lazyCreate, Files.exists(PATH));
+        Assert.assertNotEquals(createOnDemand, Files.exists(PATH));
     }
 
     private static PatternLayout createPatternLayout() {
@@ -130,14 +130,14 @@ public class FileAppenderTest {
             .withBufferedIo(false)
             .withBufferSize(1)
             .withLayout(layout)
-            .withLazyCreate(lazyCreate)
+            .withCreateOnDemand(createOnDemand)
             .build();
         // @formatter:on
         try {
             appender.start();
             final File file = new File(FILE_NAME);
             assertTrue("Appender did not start", appender.isStarted());
-            Assert.assertNotEquals(lazyCreate, Files.exists(PATH));
+            Assert.assertNotEquals(createOnDemand, Files.exists(PATH));
             long curLen = file.length();
             long prevLen = curLen;
             assertTrue("File length: " + curLen, curLen == 0);
@@ -166,7 +166,7 @@ public class FileAppenderTest {
     @Test
     public void testLockingAppender() throws Exception {
         final int logEventCount = 1;
-        writer(true, logEventCount, "test", lazyCreate, false);
+        writer(true, logEventCount, "test", createOnDemand, false);
         verifyFile(logEventCount);
     }
 
@@ -208,7 +208,7 @@ public class FileAppenderTest {
         final ProcessBuilder[] builders = new ProcessBuilder[processCount];
         for (int index = 0; index < processCount; ++index) {
             builders[index] = new ProcessBuilder("java", "-cp", classPath, ProcessTest.class.getName(),
-                    "Process " + index, logEventCount.toString(), "true", Boolean.toString(lazyCreate));
+                    "Process " + index, logEventCount.toString(), "true", Boolean.toString(createOnDemand));
         }
         for (int index = 0; index < processCount; ++index) {
             processes[index] = builders[index].start();
@@ -227,7 +227,7 @@ public class FileAppenderTest {
         verifyFile(logEventCount * processCount);
     }
 
-    private static void writer(final boolean locking, final int logEventCount, final String name, boolean lazyCreate,
+    private static void writer(final boolean locking, final int logEventCount, final String name, boolean createOnDemand,
             boolean concurrent) throws Exception {
         final Layout<String> layout = createPatternLayout();
         // @formatter:off
@@ -239,23 +239,23 @@ public class FileAppenderTest {
             .withLocking(locking)
             .withBufferedIo(false)
             .withLayout(layout)
-            .withLazyCreate(lazyCreate)
+            .withCreateOnDemand(createOnDemand)
             .build();
         // @formatter:on
-        Assert.assertEquals(lazyCreate, appender.getManager().isLazyCreate());
+        Assert.assertEquals(createOnDemand, appender.getManager().isCreateOnDemand());
         try {
             appender.start();
             assertTrue("Appender did not start", appender.isStarted());
             final boolean exists = Files.exists(PATH);
-            String msg = String.format("concurrent = %s, lazyCreate = %s, file exists = %s", concurrent, lazyCreate,
+            String msg = String.format("concurrent = %s, createOnDemand = %s, file exists = %s", concurrent, createOnDemand,
                     exists);
             // If concurrent the file might have been created (or not.)
-            // Can't really test lazyCreate && concurrent.
-            final boolean expectFileCreated = !lazyCreate;
+            // Can't really test createOnDemand && concurrent.
+            final boolean expectFileCreated = !createOnDemand;
             if (concurrent && expectFileCreated) {
                 Assert.assertTrue(msg, exists);
             } else if (expectFileCreated) {
-                Assert.assertNotEquals(msg, lazyCreate, exists);
+                Assert.assertNotEquals(msg, createOnDemand, exists);
             }
             for (int i = 0; i < logEventCount; ++i) {
                 final LogEvent logEvent = Log4jLogEvent.newBuilder().setLoggerName("TestLogger")
@@ -310,7 +310,7 @@ public class FileAppenderTest {
             final Thread thread = Thread.currentThread();
 
             try {
-                writer(lock, logEventCount, thread.getName(), lazyCreate, true);
+                writer(lock, logEventCount, thread.getName(), createOnDemand, true);
             } catch (final Exception ex) {
                 exceptionRef[0] = ex;
                 throw new RuntimeException(ex);
@@ -336,12 +336,12 @@ public class FileAppenderTest {
             }
             final boolean lock = Boolean.parseBoolean(args[2]);
 
-            final boolean lazyCreate = Boolean.parseBoolean(args[2]);
+            final boolean createOnDemand = Boolean.parseBoolean(args[2]);
 
             // System.out.println("Got arguments " + id + ", " + count + ", " + lock);
 
             try {
-                writer(lock, count, id, lazyCreate, true);
+                writer(lock, count, id, createOnDemand, true);
                 // thread.sleep(50);
 
             } catch (final Exception ex) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
index 0560301..d354b41 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
@@ -66,34 +66,34 @@ public class RollingAppenderSizeTest {
 
     private Logger logger;
 
-    private final boolean lazyCreate;
+    private final boolean createOnDemand;
 
-    @Parameterized.Parameters(name = "{0} \u2192 {1} (lazyCreate = {2})")
+    @Parameterized.Parameters(name = "{0} \u2192 {1} (createOnDemand = {2})")
     public static Collection<Object[]> data() {
         return Arrays.asList(new Object[][] { //
                 // @formatter:off
-               {"log4j-rolling-gz-lazy.xml", ".gz", true}, //
-               {"log4j-rolling-gz.xml", ".gz", false}, //
-               {"log4j-rolling-zip-lazy.xml", ".zip", true}, //
-               {"log4j-rolling-zip.xml", ".zip", false}, //
+               {"log4j-rolling-gz-lazy.xml", ".gz", true},
+               {"log4j-rolling-gz.xml", ".gz", false},
+               {"log4j-rolling-zip-lazy.xml", ".zip", true},
+               {"log4j-rolling-zip.xml", ".zip", false},
                 // Apache Commons Compress
-               {"log4j-rolling-bzip2-lazy.xml", ".bz2", true}, //
-               {"log4j-rolling-bzip2.xml", ".bz2", false}, //
-               {"log4j-rolling-deflate-lazy.xml", ".deflate", true}, //
-               {"log4j-rolling-deflate.xml", ".deflate", false}, //
-               {"log4j-rolling-pack200-lazy.xml", ".pack200", true}, //
-               {"log4j-rolling-pack200.xml", ".pack200", false}, //
-               {"log4j-rolling-xz-lazy.xml", ".xz", true}, //
-               {"log4j-rolling-xz.xml", ".xz", false}, //
+               {"log4j-rolling-bzip2-lazy.xml", ".bz2", true},
+               {"log4j-rolling-bzip2.xml", ".bz2", false},
+               {"log4j-rolling-deflate-lazy.xml", ".deflate", true},
+               {"log4j-rolling-deflate.xml", ".deflate", false},
+               {"log4j-rolling-pack200-lazy.xml", ".pack200", true},
+               {"log4j-rolling-pack200.xml", ".pack200", false},
+               {"log4j-rolling-xz-lazy.xml", ".xz", true},
+               {"log4j-rolling-xz.xml", ".xz", false},
                 });
                 // @formatter:on
     }
 
     private LoggerContextRule loggerContextRule;
 
-    public RollingAppenderSizeTest(final String configFile, final String fileExtension, final boolean lazyCreate) {
+    public RollingAppenderSizeTest(final String configFile, final String fileExtension, final boolean createOnDemand) {
         this.fileExtension = fileExtension;
-        this.lazyCreate = lazyCreate;
+        this.createOnDemand = createOnDemand;
         this.loggerContextRule = new LoggerContextRule(configFile);
         this.chain = loggerContextRule.withCleanFoldersRule(DIR);
     }
@@ -104,18 +104,18 @@ public class RollingAppenderSizeTest {
     }
 
     @Test
-    public void testIsLazyCreate() {
+    public void testIsCreateOnDemand() {
         final RollingFileAppender rfAppender = loggerContextRule.getRequiredAppender("RollingFile",
                 RollingFileAppender.class);
         final RollingFileManager manager = rfAppender.getManager();
         Assert.assertNotNull(manager);
-        Assert.assertEquals(lazyCreate, manager.isLazyCreate());
+        Assert.assertEquals(createOnDemand, manager.isCreateOnDemand());
     }
 
     @Test
     public void testAppender() throws Exception {
         final Path path = Paths.get(DIR, "rollingtest.log");
-        if (Files.exists(path) && lazyCreate) {
+        if (Files.exists(path) && createOnDemand) {
             Assert.fail(String.format("Unexpected file: %s (%s bytes)", path, Files.getAttribute(path, "size")));
         }
         for (int i = 0; i < 100; ++i) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml
index ce16320..597f102 100644
--- a/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-7z-lazy.xml
@@ -28,7 +28,7 @@
     </Console>
     <RollingFile name="RollingFile" fileName="${filename}"
                  filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.7z"
-                 lazyCreate="true">
+                 createOnDemand="true">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml
index 6697293..eed50b1 100644
--- a/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-bzip2-lazy.xml
@@ -28,7 +28,7 @@
     </Console>
     <RollingFile name="RollingFile" fileName="${filename}"
                  filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.bz2"
-                 lazyCreate="true">
+                 createOnDemand="true">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml
index d4561f7..1501db7 100644
--- a/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-deflate-lazy.xml
@@ -28,7 +28,7 @@
     </Console>
     <RollingFile name="RollingFile" fileName="${filename}"
                  filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.deflate"
-                 lazyCreate="true">
+                 createOnDemand="true">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml
index f9bfd90..fb85da5 100644
--- a/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-gz-lazy.xml
@@ -28,7 +28,7 @@
     </Console>
     <RollingFile name="RollingFile" fileName="${filename}"
                  filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.gz"
-                 lazyCreate="true">
+                 createOnDemand="true">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml
index 7355e61..db8a6dd 100644
--- a/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-pack200-lazy.xml
@@ -28,7 +28,7 @@
     </Console>
     <RollingFile name="RollingFile" fileName="${filename}"
                  filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.pack200"
-                 lazyCreate="true">
+                 createOnDemand="true">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml
index 02aa528..560741c 100644
--- a/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-xz-lazy.xml
@@ -28,7 +28,7 @@
     </Console>
     <RollingFile name="RollingFile" fileName="${filename}"
                  filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.xz"
-                 lazyCreate="true">
+                 createOnDemand="true">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4e5ef989/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml b/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml
index 2641d7f..06249d8 100644
--- a/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-zip-lazy.xml
@@ -28,7 +28,7 @@
     </Console>
     <RollingFile name="RollingFile" fileName="${filename}"
                  filePattern="target/rolling1/test1-$${date:MM-dd-yyyy}-%i.log.zip"
-                 lazyCreate="true">
+                 createOnDemand="true">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>


[4/8] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master'

Posted by rp...@apache.org.
Merge remote-tracking branch 'origin/master'


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b3d6a39b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b3d6a39b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b3d6a39b

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: b3d6a39b00b167ce1e56c2a03e2e4512ef991f08
Parents: 147f78c 93f55f3
Author: rpopma <rp...@apache.org>
Authored: Sat Aug 20 09:44:37 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Aug 20 09:44:37 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/appender/FileManager.java        |  12 +-
 .../core/appender/OutputStreamManager.java      |  18 +-
 .../core/appender/RollingFileAppender.java      | 372 ++++++++++++-------
 .../appender/rolling/RollingFileManager.java    |  50 ++-
 .../rolling/OnStartupTriggeringPolicyTest.java  |  10 +-
 .../rolling/RollingAppenderSizeTest.java        |  43 ++-
 .../rolling/RollingFileAppenderAccessTest.java  |  61 +--
 .../test/resources/log4j-rolling-7z-lazy.xml    |  59 +++
 .../test/resources/log4j-rolling-bzip2-lazy.xml |  60 +++
 .../resources/log4j-rolling-deflate-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-gz-lazy.xml    |  59 +++
 .../resources/log4j-rolling-pack200-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-xz-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-zip-lazy.xml   |  60 +++
 src/changes/changes.xml                         |   5 +-
 15 files changed, 791 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b3d6a39b/src/changes/changes.xml
----------------------------------------------------------------------


[7/8] logging-log4j2 git commit: Format: Longer lines.

Posted by rp...@apache.org.
Format: Longer lines.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/921b330c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/921b330c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/921b330c

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 921b330cc5660a902003d601c0bcdf7e9faf5aa5
Parents: 1f23297
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Aug 19 18:14:10 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Aug 19 18:14:10 2016 -0700

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/async/DaemonThreadFactory.java  | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/921b330c/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
index 90a15e0..3267c61 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
@@ -38,8 +38,7 @@ public class DaemonThreadFactory implements ThreadFactory {
 
     @Override
     public Thread newThread(final Runnable runnable) {
-        final Thread thread = new Log4jThread(group, runnable, threadNamePrefix
-                + THREAD_NUMBER.getAndIncrement(), 0);
+        final Thread thread = new Log4jThread(group, runnable, threadNamePrefix + THREAD_NUMBER.getAndIncrement(), 0);
         if (!thread.isDaemon()) {
             thread.setDaemon(true);
         }


[8/8] logging-log4j2 git commit: merge master into this branch

Posted by rp...@apache.org.
merge master into this branch


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/917afad5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/917afad5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/917afad5

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 917afad567fba5f14de59e4118714b13ca250295
Parents: b842432 921b330
Author: rpopma <rp...@apache.org>
Authored: Sat Aug 20 11:04:15 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Aug 20 11:04:15 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/appender/FileAppender.java       |  12 +-
 .../log4j/core/appender/FileManager.java        |  36 +-
 .../core/appender/OutputStreamManager.java      |  18 +-
 .../core/appender/RollingFileAppender.java      | 372 ++++++++++++-------
 .../appender/rolling/RollingFileManager.java    |  50 ++-
 .../log4j/core/async/DaemonThreadFactory.java   |   6 +-
 .../log4j/core/async/RingBufferLogEvent.java    |   4 +-
 .../log4j/core/appender/FileAppenderTest.java   |  48 +--
 .../rolling/OnStartupTriggeringPolicyTest.java  |  10 +-
 .../rolling/RollingAppenderSizeTest.java        |  43 ++-
 .../rolling/RollingFileAppenderAccessTest.java  |  61 +--
 .../test/resources/log4j-rolling-7z-lazy.xml    |  59 +++
 .../test/resources/log4j-rolling-bzip2-lazy.xml |  60 +++
 .../resources/log4j-rolling-deflate-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-gz-lazy.xml    |  59 +++
 .../resources/log4j-rolling-pack200-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-xz-lazy.xml    |  60 +++
 .../test/resources/log4j-rolling-zip-lazy.xml   |  60 +++
 src/changes/changes.xml                         |   9 +-
 19 files changed, 842 insertions(+), 245 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/917afad5/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------