GeeCON Prague 2014*
The moose likes Other Open Source Projects and the fly likes Log4j - Compress Log Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Log4j - Compress Log Files" Watch "Log4j - Compress Log Files" New topic
Author

Log4j - Compress Log Files

Kasi Viswan
Ranch Hand

Joined: Sep 27, 2008
Posts: 42
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Sep 27, 2008
Posts: 42
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

Joined: Jul 19, 2009
Posts: 110
Hi Kasi,

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

Tahnks,
Tanzy.


Roll with punchers, there is always tomorrow.
Techie Blog -- http://jtanzy.blogspot.com/
 
jQuery in Action, 2nd edition
 
subject: Log4j - Compress Log Files