Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log4j - Compress Log Files

 
Kasi Viswan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a swing web sevice client. Am using Log4j for logging with RollingFileAppender. The log files that are generated are taking up a lot of disk space. Is there a configuration property in Log4j that allows the rolled over file to be compressed or is it possible to write compressed log files.

Here is my current log4j configuration:



Any help is much appreciated.

Thanks
Kasi
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kasi Viswan wrote:Is there a configuration property in Log4j that allows the rolled over file to be compressed or is it possible to write compressed log files.


No, there isn't. You could write your own subclass of that appender which zips a log file after closing. Or you could do what I do, which is to have a scheduled job which zips log files which are over a week old and deletes zip files which are over a year old. Choose your own intervals, of course, but I read log files often enough, and having to unzip them first is tedious, that's why I keep them unzipped for a week.
 
Kasi Viswan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Paul, I will only be able to use the first option you suggested as in my case the log files will grow huge in few hours depending on the number of threads and the data processed, so i won't even be able to set a predefined time to compress the logs.

As I understand i have to write a AppenderClass extending RollingFileAppender, which method should i override, is it the close(). Is this where i should I should compress the log file that is closed, How do i get handle to the file that is being closed. Please advice.

I have one more question on Log4j,
I create more than one log file in my application, how do i relinquish control from the log files generated after a data run while still having my Swing client running.

Thanks
Kasi
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kasi,

Can you please elaborate more, what is your actual need..

Tahnks,
Tanzy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic