Skip to content

Commit b627c71

Browse files
committed
Added Zstandard compression support (#1508, #1514)
2 parents 85b49eb + 1123925 commit b627c71

File tree

9 files changed

+69
-12
lines changed

9 files changed

+69
-12
lines changed

log4j-core-test/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@
354354
<artifactId>xz</artifactId>
355355
<scope>test</scope>
356356
</dependency>
357+
<dependency>
358+
<groupId>com.github.luben</groupId>
359+
<artifactId>zstd-jni</artifactId>
360+
<scope>test</scope>
361+
</dependency>
357362
</dependencies>
358363

359364
<build>

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public class RollingAppenderSizeTest {
5959
"bz2",
6060
"deflate",
6161
"pack200",
62-
"xz");
62+
"xz",
63+
"zst");
6364

6465
static Stream<Arguments> parameters() {
6566
return FILE_EXTENSIONS.stream().flatMap(fileExtension -> {

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileExtension.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,41 @@ public Action createCompressAction(final String renameTo, final String compresse
4646
@Override
4747
public Action createCompressAction(final String renameTo, final String compressedName, final boolean deleteSource,
4848
final int compressionLevel) {
49-
// One of "gz", "bzip2", "xz", "pack200", or "deflate".
49+
// One of "gz", "bzip2", "xz", "zst", "pack200", or "deflate".
5050
return new CommonsCompressAction("bzip2", source(renameTo), target(compressedName), deleteSource);
5151
}
5252
},
5353
DEFLATE(".deflate") {
5454
@Override
5555
public Action createCompressAction(final String renameTo, final String compressedName, final boolean deleteSource,
5656
final int compressionLevel) {
57-
// One of "gz", "bzip2", "xz", "pack200", or "deflate".
57+
// One of "gz", "bzip2", "xz", "zst", "pack200", or "deflate".
5858
return new CommonsCompressAction("deflate", source(renameTo), target(compressedName), deleteSource);
5959
}
6060
},
6161
PACK200(".pack200") {
6262
@Override
6363
public Action createCompressAction(final String renameTo, final String compressedName, final boolean deleteSource,
6464
final int compressionLevel) {
65-
// One of "gz", "bzip2", "xz", "pack200", or "deflate".
65+
// One of "gz", "bzip2", "xz", "zst", "pack200", or "deflate".
6666
return new CommonsCompressAction("pack200", source(renameTo), target(compressedName), deleteSource);
6767
}
6868
},
6969
XZ(".xz") {
7070
@Override
7171
public Action createCompressAction(final String renameTo, final String compressedName, final boolean deleteSource,
7272
final int compressionLevel) {
73-
// One of "gz", "bzip2", "xz", "pack200", or "deflate".
73+
// One of "gz", "bzip2", "xz", "zstd", "pack200", or "deflate".
7474
return new CommonsCompressAction("xz", source(renameTo), target(compressedName), deleteSource);
7575
}
76+
},
77+
ZSTD(".zst") {
78+
@Override
79+
public Action createCompressAction(final String renameTo, final String compressedName, final boolean deleteSource,
80+
final int compressionLevel) {
81+
// One of "gz", "bzip2", "xz", "zstd", "pack200", or "deflate".
82+
return new CommonsCompressAction("zstd", source(renameTo), target(compressedName), deleteSource);
83+
}
7684
};
7785

7886
public static FileExtension lookup(final String fileExtension) {

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/CommonsCompressAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public final class CommonsCompressAction extends AbstractAction {
3636
private static final int BUF_SIZE = 8192;
3737

3838
/**
39-
* Compressor name. One of "gz", "bzip2", "xz", "pack200" or "deflate".
39+
* Compressor name. One of "gz", "bzip2", "xz", "zst", "pack200" or "deflate".
4040
*/
4141
private final String name;
4242

@@ -58,7 +58,7 @@ public final class CommonsCompressAction extends AbstractAction {
5858
/**
5959
* Creates new instance of Bzip2CompressAction.
6060
*
61-
* @param name the compressor name. One of "gz", "bzip2", "xz", "pack200", or "deflate".
61+
* @param name the compressor name. One of "gz", "bzip2", "xz", "zst", "pack200", or "deflate".
6262
* @param source file to compress, may not be null.
6363
* @param destination compressed file, may not be null.
6464
* @param deleteSource if true, attempt to delete file on completion. Failure to delete does not cause an exception
@@ -88,7 +88,7 @@ public boolean execute() throws IOException {
8888
/**
8989
* Compresses a file.
9090
*
91-
* @param name the compressor name, i.e. "gz", "bzip2", "xz", "pack200", or "deflate".
91+
* @param name the compressor name, i.e. "gz", "bzip2", "xz", "zstd", "pack200", or "deflate".
9292
* @param source file to compress, may not be null.
9393
* @param destination compressed file, may not be null.
9494
* @param deleteSource if true, attempt to delete file on completion. Failure to delete does not cause an exception

log4j-parent/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
<woodstox.version>6.5.1</woodstox.version>
134134
<xmlunit.version>2.9.1</xmlunit.version>
135135
<xz.version>1.9</xz.version>
136+
<zstd.version>1.5.5-6</zstd.version>
136137

137138
<!-- =====================================================
138139
Pinned transitive dependency version properties (in alphabetical order)
@@ -996,6 +997,12 @@
996997
<version>${xz.version}</version>
997998
</dependency>
998999

1000+
<dependency>
1001+
<groupId>com.github.luben</groupId>
1002+
<artifactId>zstd-jni</artifactId>
1003+
<version>${zstd.version}</version>
1004+
</dependency>
1005+
9991006
</dependencies>
10001007
</dependencyManagement>
10011008

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to you under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xmlns="http://logging.apache.org/log4j/changelog"
20+
xsi:schemaLocation="http://logging.apache.org/log4j/changelog https://logging.apache.org/log4j/changelog-0.1.1.xsd"
21+
type="added">
22+
<issue id="1508" link="https://github.com/apache/logging-log4j2/issues/1508"/>
23+
<issue id="1514" link="https://github.com/apache/logging-log4j2/pull/1514"/>
24+
<author id="github:anuragagarwal561994" name="Anurag Agarwal"/>
25+
<author id="github:vy"/>
26+
<description format="asciidoc">Added http://www.zstd.net/[ZStandard compression] support</description>
27+
</entry>

src/site/_release-notes/_2.21.0.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The module name of four bridges (`log4j-slf4j-impl`, `log4j-slf4j2-impl`, `log4j
4747
=== Added
4848
4949
* Added marker parent support to `JsonTemplateLayout` (https://github.com/apache/logging-log4j2/pull/1381[1381])
50+
* Added http://www.zstd.net/[ZStandard compression] support (https://github.com/apache/logging-log4j2/issues/1508[1508], https://github.com/apache/logging-log4j2/pull/1514[1514])
5051
* Added a warning for incorrect syntax of highlighting styles (https://github.com/apache/logging-log4j2/issues/1545[1545], https://github.com/apache/logging-log4j2/pull/1637[1637])
5152
5253
=== Changed

src/site/xdoc/manual/appenders.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,10 +3322,14 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
33223322
is present it will be replaced with the current date and time values. If the pattern contains an integer
33233323
it will be incremented on each rollover. If the pattern contains both a date/time and integer
33243324
in the pattern the integer will be incremented until the result of the date/time pattern changes. If
3325-
the file pattern ends with ".gz", ".zip", ".bz2", ".deflate", ".pack200", or ".xz" the resulting archive
3325+
the file pattern ends with ".gz", ".zip", ".bz2", ".deflate", ".pack200", ".zst" or ".xz" the resulting archive
33263326
will be compressed using the compression scheme that matches the suffix. The formats bzip2, Deflate,
3327-
Pack200 and XZ require <a href="https://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.
3328-
In addition, XZ requires <a href="https://tukaani.org/xz/java.html">XZ for Java</a>.
3327+
Pack200, XZ, and ZStandard require <a href="https://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.
3328+
In addition:
3329+
<ul>
3330+
<li>XZ requires <a href="https://tukaani.org/xz/java.html">xz-java</a></li>
3331+
<li>ZStandard requires <a href="https://github.com/luben/zstd-jni">zstd-jni</a></li>
3332+
</ul>
33293333
The pattern may also contain lookup references that can be resolved at runtime such as is shown in the example
33303334
below.
33313335
</p>

src/site/xdoc/runtime-dependencies.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@
285285
<tr>
286286
<td>Bzip2, Deflate, Pack200, and XZ compression on rollover</td>
287287
<td><a href="https://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>.
288-
In addition, XZ requires <a href="https://tukaani.org/xz/java.html">XZ for Java</a>.
288+
In addition:
289+
<ul>
290+
<li>XZ requires <a href="https://tukaani.org/xz/java.html">xz-java</a></li>
291+
<li>ZStandard requires <a href="https://github.com/luben/zstd-jni">zstd-jni</a></li>
292+
</ul>
289293
</td>
290294
</tr>
291295
<tr>

0 commit comments

Comments
 (0)