That is quite an interesting problem. Without thinking about it too much, I think your best bet to extend an appender so that it can replace itself with another. For example, see the source code of org.apache.log4j.varia.FallbackErrorHandler which performs a similar task.

At 03:02 PM 9/5/2003 -0400, you wrote:
Hello,

My organization is switching to log4j. I implemented an extension to the old
logging package so that I could switch the log message destinations (two
files)
back and forth. Now I need to do the same with log4j.

Here is what I did, please let me know if this will work, or any better
ways.

1) extended Logger

public class RecoverLog4jLogger extends Logger {

    RecoverLog4jLogger(String name) {
        super(name);
    }

    synchronized public void replaceAppender(Appender oldAppender, Appender
newA
ppender) {
        super.removeAppender(oldAppender);
        super.addAppender(newAppender);
    }
}

2) implemented custom LoggerFactory

class RecoverLog4jFactory implements LoggerFactory {

    RecoverLog4jFactory() {
    }

    public RecoverLog4jLogger makeNewLoggerInstance(String name) {
        return new RecoverLog4jLogger(name);
    }
}


The idea is upon receiving request to switch log file, the 'replaceAppender' will be called. By grouping the 'removeAppender' and 'addAppender' together, I hope message won't get lost (or duplicated), since there is a single lock and single lock acquire/release by doing this.

Two questions:
1) Will this guarantee no lost message or duplicated message?
2) Will the 'replaceAppender' API be generally useful? If so, can that make
into
   the log4j framework per se?

Thanks for your help.

Glenn


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

-- Ceki G�lc�

     For log4j documentation consider "The complete log4j manual"
     ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp

     See you in November at ApacheCon US 2003 in Las Vegas.
     http://apachecon.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to