Skip to content

[main] Honor compressionLevel in the rollover strategies (#4234 port) - #4448

Open
katstack wants to merge 2 commits into
apache:mainfrom
katstack:port-4234-compression-level
Open

katstack wants to merge 2 commits into
apache:mainfrom
katstack:port-4234-compression-level

Conversation

@katstack

@katstack katstack commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Port of #4234 to main. In main, a configured compressionLevel is ignored because the strategies always pass an empty options map to CompressActionFactory.

The attribute is passed in the compressionLevel option and is interpreted as the native compression level of the algorithm. It applies to zip, gz, bzip2, deflate and zstd, as in 2.x. A level the algorithm does not support is reported once and the default level is used, except for zstd, which adjusts levels outside of its range. With a level, the compressor of the algorithm is created directly instead of through the CompressorStreamProvider, because that interface cannot take a level.

These algorithms ignore the option with a warning:

Differences from 2.x

  • An unsupported level is reported at the first rollover, when the first compression action is created. 2.x reports it at startup, when the RollingFileManager is created.
  • Reporting it at startup here would require one of the following, so I implemented neither:
    • a new method on CompressActionFactory to validate the options, which extends the public API,
    • calling createCompressAction with placeholder file names just to trigger the warning, which could have side effects in third-party factories.
  • A zstd level outside of the range of Zstandard is adjusted by Zstandard without a warning. 2.x reports it and uses the default level.

… port)

Pass the `compressionLevel` attribute of `DefaultRolloverStrategy` and `DirectWriteRolloverStrategy` to the `CompressActionFactory` in the `compressionLevel` option. The attribute was dropped when the compression moved to `log4j-compress`, so a level set in a configuration was ignored.

The level is the native level of the algorithm and applies to `zip`, `gz`, `bzip2`, `deflate` and `zstd`, as in 2.x. A level rejected by the algorithm is reported once and the default level is used. Algorithms without configurable levels (`xz`, `lzma`, `lz4-*`, `snappy-framed`) ignore the option with a warning.
@ramanathan1504

Copy link
Copy Markdown
Contributor

The port keeps the contract agreed on #4234, and the new tests catch a broken factory or validator.
@ppkarwasz, #2950 planned to drop compressionLevel in 3.x and #2921 removed it from main. Do we want it back in 3.0?

…gelog entry

Run the configuration test for both strategies with a tempCompressedFilePattern too, which compresses into a temporary file first. Passing no options on that path now fails the test.

Use a one line changelog description and list this pull request next to the one it ports.
@ramanathan1504 ramanathan1504 added minor API change appenders:Rolling Affects log file rolling functionality enhancement Additions or updates to features java Pull requests that update Java code port-done No further port needed: all required ports are merged, or none was needed labels Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

appenders:Rolling Affects log file rolling functionality enhancement Additions or updates to features java Pull requests that update Java code minor API change port-done No further port needed: all required ports are merged, or none was needed

Projects

Development

Successfully merging this pull request may close these issues.

2 participants