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]