views:

254

answers:

2

We have a requirment which requires to have an Handler that is extended from Java logging and allows to have the files rotated on daily basis.

Currently Java util logging do have the support of rotation based on file size by using File Handler. It doesnt support rotation on daily basis. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6350749

So , what we are looking is for such an appender that allows daily rotation . We would like to write such handler and which is the appropriate handler to extend for ... StreamHandler or FileHandler ? And other questions are , is there way we can configure 2 different files for a single handler say FileHandler say for eg , we would like some kind of messages need to be captured in one file and other messages in other file.

Would appreciate for any comments.

A: 

You can write a scheduler (Quartz scheduler or something similar) that runs at 00:00 hours daily. Let the code do the FileHandler stuff and perform file rotation.

navr
A: 

Log rotation - Tell management that Apache is one of the largest code houses in the world and I am sure there are millions of projects that use it. But since you have reiterated "Management decision" you could write your own FileHandler or use Java File handler, write your tasks, write the many hundred scenarios of tests (like quartz rolling the file when the handler is appending them)

FileHander writing to two files - Either subclass the FileHandler (The filehandler should know when to send to these two files) But the prescribed solutions would be to use two actually different loggers with two different names with two appenders attached. A single java source can do logging to as many loggers as it wants, so

class MyClass {
    Logger fileLogger = Logger.getLogger("something.mapped.to.file");
    Logger dbLogger = Logger.getLogger("something.mapped.to.db");

    public void someMethod() {
        dbLogger.log("XXX);
        fileLogger.log("YYY");
    }
}
Calm Storm