Can java.util.logging be configured to use compressed log files?

Is it possible to configure java.util.logging to compress log files when it "rolls" to a new log file? For example, extracting from my log configuration file is as follows:

java.util.logging.FileHandler.level = ALL java.util.logging.FileHandler.pattern = /blah.log java.util.logging.FileHandler.limit = 10000000 java.util.logging.FileHandler.count = 5 

Ideally, I would like current log messages to be written to blah.log.0, keeping blah.log.1.gz, blah.log.2.gz, etc.

Also note that I do not want to use a different logging structure.

+6
java logging
source share
3 answers

Yes, but you have to write your own file handler. Just copy the source code of FileHandler into your project (you cannot extend the class in any useful way) and change the open() method of MeteredStream .

After that, just use the normal configuration to use the new handler.

+8
source share

No, not washing it yourself, but what you can do is schedule a cron job that does this regularly. This is likely to be the fastest solution.

+3
source share

I doubt it is available as part of Java logging. You can set up a shell script that compresses all previous log files daily.

If you really want to do this in java, you may have to write your own file handler.
Check the method that creates the new file and tries to compress the previous one.

+2
source share

All Articles