This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 18541
    
    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/
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Log4j - Compress Log Files
 
Similar Threads
New to log4j
Log4j and WSAD 5.0
servlet loggin not working (log4j)
is there a need for both log4j.properties file and log4j.xml file in the same project
Help required to log messages in tomcat :"Not able to log messages to separate files"