ramanathan1504 opened a new issue, #4487:
URL: https://github.com/apache/logging-log4j2/issues/4487
On current 2.x, a rolling file appender with a `.zst` `filePattern` fails to
compress on every rollover when the application has commons-compress 1.27.1 or
1.26.2 (commons-compress is an optional dependency of log4j-core).
`ZstdCompressAction` calls `ZstdCompressorOutputStream.builder()` and
`ZstdConstants`, which only exist since commons-compress 1.28.0. Each rollover
leaves a 0-byte `app-N.log.zst` next to the uncompressed `app-N.log`, and the
error is reported only at StatusLogger WARN, so nothing is printed by default.
2.26.1 compresses correctly on 1.26.2, 1.27.1 and 1.28.0.
## Configuration
**Version:** 2.x at `ea28f5a78b` (2.27.0-SNAPSHOT); not affected: 2.26.1
**Operating system:** macOS
**JDK:** OpenJDK 17.0.14
## Logs
With `-Dlog4j2.StatusLogger.level=WARN`, commons-compress 1.27.1, zstd-jni
1.5.7-24:
```
Log4j2-TF-1-RollingFileManager-2 WARN Exception reported by action 'class
org.apache.logging.log4j.core.appender.rolling.RollingFileManager$AsyncAction'
java.lang.RuntimeException: java.lang.NoSuchMethodError:
'org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream$Builder
org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream.builder()'
at
org.apache.logging.log4j.core.appender.rolling.action.AbstractAction.run(AbstractAction.java:69)
Caused by: java.lang.NoSuchMethodError:
...ZstdCompressorOutputStream.builder()'
at
org.apache.logging.log4j.core.appender.rolling.action.internal.ZstdCompressAction.createCompressorOutputStream(ZstdCompressAction.java:80)
at
org.apache.logging.log4j.core.appender.rolling.action.internal.CompressActionSupport.execute(CompressActionSupport.java:97)
```
With `compressionLevel="5"` on `DefaultRolloverStrategy`:
```
Caused by: java.lang.NoClassDefFoundError:
org/apache/commons/compress/compressors/zstandard/ZstdConstants
at
org.apache.logging.log4j.core.appender.rolling.action.internal.ZstdCompressAction.resolveCompressionLevel(ZstdCompressAction.java:56)
at
org.apache.logging.log4j.core.appender.rolling.action.internal.ZstdCompressAction.createCompressorOutputStream(ZstdCompressAction.java:79)
```
At the default StatusLogger level, nothing is printed. Directory after two
rollovers:
```
app-1.log=700B app-1.log.zst=0B app-2.log=700B app-2.log.zst=0B app.log=700B
```
With 2.26.1 on the same classpath: `app-1.log.zst=140B app-2.log.zst=140B
app.log=700B`.
## Reproduction
Classpath: log4j-api and log4j-core at 2.x HEAD,
`org.apache.commons:commons-compress:1.27.1`,
`com.github.luben:zstd-jni:1.5.7-24`.
```xml
<Configuration>
<Appenders>
<RollingFile name="zst" fileName="logs/app.log"
filePattern="logs/app-%i.log.zst">
<PatternLayout pattern="%m%n"/>
<SizeBasedTriggeringPolicy size="100 MB"/>
<DefaultRolloverStrategy max="5"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="INFO"><AppenderRef ref="zst"/></Root>
</Loggers>
</Configuration>
```
```java
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Logger logger = LogManager.getLogger("zst");
RollingFileAppender appender = ctx.getConfiguration().getAppender("zst");
for (int i = 1; i <= 50; i++) logger.info("line-" + i);
appender.getManager().rollover();
for (int i = 51; i <= 100; i++) logger.info("line-" + i);
ctx.stop(30, TimeUnit.SECONDS);
```
Expected: `logs/app-1.log.zst` is a valid Zstandard archive holding lines
1-50, and there is no `logs/app-1.log`. Observed on 2.x HEAD with
commons-compress 1.27.1 or 1.26.2: `logs/app-1.log.zst` is 0 bytes and
`logs/app-1.log` remains uncompressed. With commons-compress 1.28.0, or with
Log4j 2.26.1 on any of the three versions, the archive is valid.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]