Sampathkumar
Sampathkumar

Reputation: 121

Zipping the files in Log4j

I have used SizeBasedTriggeringPolicy in LOG4J, it splits the files based on the size. My question here is that I want to zip all the files within a date into single folder.

Example:

log_20160709_1.txt

log_20160709_2.txt

log_20160709.3.txt

all the above files have to zip into log_20160709.zip.

I am able to zip the individual files but I want all to be in single zip folder.

Please provide the suggestion for it.

Upvotes: 1

Views: 168

Answers (2)

Srinivasu
Srinivasu

Reputation: 1235

Try this pattern

<param name="FileNamePattern" value="/wombat/foo.%d{yyyy-MM-hh}.gz"/>

Upvotes: 0

Sanjeev
Sanjeev

Reputation: 9946

You have couple of options to do that

  1. Use TimeBasedRollingPolicy

Automatic file compression

TimeBasedRollingPolicy supports automatic file compression. This feature is enabled if the value of the FileNamePattern option ends with .gz or .zip.

  1. write a batch job which will run at End Of the Day Say midnight and zips all files of the day into a single zip file.

Upvotes: 1

Related Questions