You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2015/07/08 23:04:42 UTC

logging-log4j2 git commit: [LOG4J2-1077] Support additional Apache Commons Compress compression formats on rollover: Deflate, Pack200, XY.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master de89ca4e2 -> 9c5871adc


[LOG4J2-1077] Support additional Apache Commons Compress compression
formats on rollover: Deflate, Pack200, XY.

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

Branch: refs/heads/master
Commit: 9c5871adc3a72c856f609b2371db68dba253b096
Parents: de89ca4
Author: ggregory <gg...@apache.org>
Authored: Wed Jul 8 14:04:38 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Wed Jul 8 14:04:38 2015 -0700

----------------------------------------------------------------------
 .../rolling/DefaultRolloverStrategy.java        | 65 +++++++++++++-------
 log4j-core/src/site/xdoc/index.xml              |  5 +-
 .../rolling/RollingAppenderSizeTest.java        |  4 ++
 .../test/resources/log4j-rolling-deflate.xml    | 59 ++++++++++++++++++
 .../test/resources/log4j-rolling-pack200.xml    | 59 ++++++++++++++++++
 .../src/test/resources/log4j-rolling-xy.xml     | 59 ++++++++++++++++++
 src/changes/changes.xml                         |  3 +
 src/site/xdoc/manual/appenders.xml              | 11 ++--
 src/site/xdoc/runtime-dependencies.xml          |  5 +-
 9 files changed, 238 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9c5871ad/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
index d538d90..da3a778 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
@@ -96,8 +96,30 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
         BZIP2(".bz2") {
             Action createCompressAction(String renameTo, String compressedName, boolean deleteSource,
                     int compressionLevel) {
+                // One of "gz", "bzip2", "xz", "pack200", or "deflate".
                 return new CommonsCompressAction("bzip2", new File(baseName(renameTo)), new File(compressedName), deleteSource);
-            }
+            }            
+        },
+        DEFALTE(".deflate") {
+            Action createCompressAction(String renameTo, String compressedName, boolean deleteSource,
+                    int compressionLevel) {
+                // One of "gz", "bzip2", "xz", "pack200", or "deflate".
+                return new CommonsCompressAction("deflate", new File(baseName(renameTo)), new File(compressedName), deleteSource);
+            }            
+        },
+        PACK200(".pack200") {
+            Action createCompressAction(String renameTo, String compressedName, boolean deleteSource,
+                    int compressionLevel) {
+                // One of "gz", "bzip2", "xz", "pack200", or "deflate".
+                return new CommonsCompressAction("pack200", new File(baseName(renameTo)), new File(compressedName), deleteSource);
+            }            
+        },
+        XY(".xy") {
+            Action createCompressAction(String renameTo, String compressedName, boolean deleteSource,
+                    int compressionLevel) {
+                // One of "gz", "bzip2", "xz", "pack200", or "deflate".
+                return new CommonsCompressAction("xy", new File(baseName(renameTo)), new File(compressedName), deleteSource);
+            }            
         };
 
         private final String extension;
@@ -226,24 +248,13 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
      * @return true if purge was successful and rollover should be attempted.
      */
     private int purgeAscending(final int lowIndex, final int highIndex, final RollingFileManager manager) {
-        int suffixLength = 0;
-
         final List<FileRenameAction> renames = new ArrayList<>();
         final StringBuilder buf = new StringBuilder();
 
         // LOG4J2-531: directory scan & rollover must use same format
         manager.getPatternProcessor().formatFileName(subst, buf, highIndex);
-
         String highFilename = subst.replace(buf);
-
-        if (FileExtensions.GZIP.isExtensionFor(highFilename)) {
-            suffixLength = FileExtensions.GZIP.length();
-        } else if (FileExtensions.ZIP.isExtensionFor(highFilename)) {
-            suffixLength = FileExtensions.ZIP.length();
-        } else if (FileExtensions.BZIP2.isExtensionFor(highFilename)) {
-            suffixLength = FileExtensions.BZIP2.length();
-        }
-
+        final int suffixLength = suffixLength(highFilename);
         int maxIndex = 0;
 
         for (int i = highIndex; i >= lowIndex; i--) {
@@ -345,8 +356,6 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
      * @return true if purge was successful and rollover should be attempted.
      */
     private int purgeDescending(final int lowIndex, final int highIndex, final RollingFileManager manager) {
-        int suffixLength = 0;
-
         final List<FileRenameAction> renames = new ArrayList<>();
         final StringBuilder buf = new StringBuilder();
 
@@ -354,14 +363,7 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
         manager.getPatternProcessor().formatFileName(subst, buf, lowIndex);
 
         String lowFilename = subst.replace(buf);
-
-        if (FileExtensions.GZIP.isExtensionFor(lowFilename)) {
-            suffixLength = FileExtensions.GZIP.length();
-        } else if (FileExtensions.ZIP.isExtensionFor(lowFilename)) {
-            suffixLength = FileExtensions.ZIP.length();
-        } else if (FileExtensions.BZIP2.isExtensionFor(lowFilename)) {
-            suffixLength = FileExtensions.BZIP2.length();
-        }
+        final int suffixLength = suffixLength(lowFilename);
 
         for (int i = lowIndex; i <= highIndex; i++) {
             File toRename = new File(lowFilename);
@@ -439,6 +441,23 @@ public class DefaultRolloverStrategy implements RolloverStrategy {
         return lowIndex;
     }
 
+    private int suffixLength(String lowFilename) {
+        if (FileExtensions.GZIP.isExtensionFor(lowFilename)) {
+            return FileExtensions.GZIP.length();
+        } else if (FileExtensions.ZIP.isExtensionFor(lowFilename)) {
+            return FileExtensions.ZIP.length();
+        } else if (FileExtensions.BZIP2.isExtensionFor(lowFilename)) {
+            return FileExtensions.BZIP2.length();
+        } else if (FileExtensions.DEFALTE.isExtensionFor(lowFilename)) {
+            return FileExtensions.DEFALTE.length();
+        } else if (FileExtensions.PACK200.isExtensionFor(lowFilename)) {
+            return FileExtensions.PACK200.length();
+        } else if (FileExtensions.XY.isExtensionFor(lowFilename)) {
+            return FileExtensions.XY.length();
+        }
+        return 0;
+    }
+
     /**
      * Perform the rollover.
      * @param manager The RollingFileManager name for current active log file.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9c5871ad/log4j-core/src/site/xdoc/index.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/site/xdoc/index.xml b/log4j-core/src/site/xdoc/index.xml
index 4332b62..e01d9fc 100644
--- a/log4j-core/src/site/xdoc/index.xml
+++ b/log4j-core/src/site/xdoc/index.xml
@@ -56,8 +56,9 @@
                 <li>The NoSQL Appender with Apache CouchDB provider requires the LightCouch CouchDB client library.</li>
                 <li>The NoSQL Appender can be customized with a user-supplied provider, which will require the
                 appropriate client library.</li>
-                <li>bzip2 compression at rollover requires
-                <a href="http://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.</li>                
+                <li>bzip2, Deflate, Pack200, and XZ compression on rollover requires
+                <a href="http://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>. In addition, 
+                XZ requires <a href="http://tukaani.org/xz/java.html">XZ for Java</a>.</li>                
             </ul>
         </section>
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9c5871ad/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 e7aea45..8181b2c 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
@@ -53,7 +53,11 @@ public class RollingAppenderSizeTest {
                 new Object[][]{
                         { "log4j-rolling-gz.xml", ".gz" },
                         { "log4j-rolling-zip.xml", ".zip" },
+                        // Apache Commons Compress
                         { "log4j-rolling-bzip2.xml", ".bz2" },
+                        { "log4j-rolling-deflate.xml", ".deflate" },
+                        { "log4j-rolling-pack200.xml", ".pack200" },
+                        { "log4j-rolling-xy.xml", ".xy" },
                 }
         );
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9c5871ad/log4j-core/src/test/resources/log4j-rolling-deflate.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-deflate.xml b/log4j-core/src/test/resources/log4j-rolling-deflate.xml
new file mode 100644
index 0000000..e4afa91
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-deflate.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.deflate">
+      <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/9c5871ad/log4j-core/src/test/resources/log4j-rolling-pack200.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-pack200.xml b/log4j-core/src/test/resources/log4j-rolling-pack200.xml
new file mode 100644
index 0000000..8d1feb0
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-pack200.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.pack200">
+      <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/9c5871ad/log4j-core/src/test/resources/log4j-rolling-xy.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-xy.xml b/log4j-core/src/test/resources/log4j-rolling-xy.xml
new file mode 100644
index 0000000..e82a7d5
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-xy.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.xy">
+      <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/9c5871ad/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 21ec00b..96542d6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -27,6 +27,9 @@
       <action issue="LOG4J2-1075" dev="rpopma" type="add">
         Added support for compressing to bzip2 format on file rollover.
       </action>
+      <action issue="LOG4J2-1077" dev="ggregory" type="add">
+        Support additional Apache Commons Compress compression formats on rollover: Deflate, Pack200, XY.
+      </action>
       <action issue="LOG4J2-767" dev="ggregory" type="add" due-to="Mikael Ståldal">
         New module for Liquibase integration.
       </action>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9c5871ad/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index e2f85eb..6c3f5f2 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -2146,11 +2146,12 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
                 is present it will be replaced with the current date and time values. If the pattern contains an integer
                 it will be incremented on each rollover. If the pattern contains both a date/time and integer
                 in the pattern the integer will be incremented until the result of the date/time pattern changes. If
-                the file pattern ends with ".gz", ".zip" or ".bz2" the resulting archive will be compressed using the
-                compression scheme that matches the suffix. (bzip2 requires 
-                <a href="http://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.)
-                The pattern may also contain lookup references that
-                can be resolved at runtime such as is shown in the example below.
+                the file pattern ends with ".gz", ".zip", ".bz2", ".deflate", ".pack200", or ".xz" the resulting archive 
+                will be compressed using the compression scheme that matches the suffix. The formats bzip2, Deflate, 
+                Pack200 and XZ require <a href="http://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.
+                In addition, XZ requires <a href="http://tukaani.org/xz/java.html">XZ for Java</a>. 
+                The pattern may also contain lookup references that can be resolved at runtime such as is shown in the example 
+                below.
               </p>
               <p>The default rollover strategy supports two variations for incrementing the counter. The first is
                 the "fixed window" strategy. To illustrate how it works, suppose that the min attribute is set to 1,

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9c5871ad/src/site/xdoc/runtime-dependencies.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/runtime-dependencies.xml b/src/site/xdoc/runtime-dependencies.xml
index 227dfc3..af8447f 100644
--- a/src/site/xdoc/runtime-dependencies.xml
+++ b/src/site/xdoc/runtime-dependencies.xml
@@ -91,8 +91,9 @@
           </td>
         </tr>
         <tr>
-          <td>bzip2 compression at rollover</td>
-          <td><a href="http://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>
+          <td>bzip2, Deflate, Pack200, and XZ compression on rollover</td>
+          <td><a href="http://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.
+            In addition, XZ requires <a href="http://tukaani.org/xz/java.html">XZ for Java</a>.
           </td>
         </tr>
       </table>