Howto force log4j2 to compress a file even if it does not have a standard gz or zip extension

StackOverflow https://stackoverflow.com/questions/23344882

  •  11-07-2023
  •  | 
  •  

Pregunta

While defining a RollingRandomAccessFile Appender or similar appender for the attribute "filepattern" if we specify standard extension as gz/zip log4j2 claims to automatically compress the file.

<RollingRandomAccessFile 
             name="RollingRandomAccessFile" 
             fileName="/var/log/myapp.log"
             filePattern="/var/log/myapp.%d{yyyy_MM_dd}.%i.gz">

I wish to use a different extension instead of gz/zip but still have the file compressed using the gzip compression.

Is there a way to achieve this?

¿Fue útil?

Solución

As of log4j2-rc1 this is not possible. The decision to compress or not, and which compression algorithm to use is currently determined by the "filePattern" file name extension.

If you want to decouple these, perhaps with an additional attribute in the configuration for RollingRandomAccessFile and RollingFile, then please raise a feature request in Log4j2's Jira issue tracker. Providing a patch with unit tests would be ideal. :-)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top