Hi Curt,
You write:
ConsoleAppender is such a widely used class that any change in
behavior has a good likelihood of somebody being negatively affected
by the change. Witness the last iteration of changing the behavior
of ConsoleAppender in bugs 31506, 37122, and 37452
(http:// issues.apache.org/bugzilla/show_bug.cgi?id=31056)
I see the problem - although I would think relying on the
writer not being flushed is a Bad Idea, after all then you
rely on the nondeterministic behaviour "lose from 0 to N lines" ;-)
May I suggest to add a reset() method to ConsoleAppender,
whose sole purpose it is to comment the problem in question?
(That shouldn't change existing behaviour, right?)
/**
Clear internal references to the writer and other variables.
When this method is called, there might still be unflushed
lines in the superclass writer's buffer. Override this method
to flush WriterAppender.qw if you want to make sure everything has
been written out.
*/
protected
void reset() {
super.reset()
}
I would suggest that you derive your class off of WriterAppender
which does not have the closeWriter() override. You may end up
duplicating some code from ConsoleAppender, but a little duplicate
code for you is a better choice to me than upsetting someone who
depended on ConsoleAppender not calling flush() on shutdown.
Obviously if you wanted assignment compatibility with WriterAppender,
that wouldn't be an option.
I have modified the reset() method of my own subclass
of ConsoleAppender (the "AlphaAppender"). It just flushes the
QuietWriter of the WriterAppender before WriterAppender.reset(),
like this:
@Override
protected void reset() {
// reset() is called after the properties have been set() and after the
// Layout has returned from initialization, as well as on shutdown.
// The superclass should flush the streams!! It does not, so we do it.
// This is important if we are in a shutdown() and about to properly
// exit() and do not have 'immediateFlush' on.
// If we just call exit(), of course, any half-empty buffer will be lost.
if (qw!=null) {
qw.flush(); // this is the QuietWriter
}
super.reset(); // will unreference 'qw' but NOT close STDOUT/STDERR
// Nothing more can be appended now, in principle (but the superclass
// actually did NOT close STDERR and STDOUT, of course).
// It looks like after a reset(), further appends cannot be performed
// as the superclass WriterAppender.checkEntryConditions() will return
// false, prohibiting further appends.
// This will be the case until activateOptions() is called, which
// re-initializes the writer.
LogLog.debug(CLASS + ".reset: has been called");
eventQueue.add(new LoggingEvent(Logger.class.getName(), Logger.getLogger(CLASS +
".reset"), Level.WARN, "reset() has been called", null));
boolean alsoJoin;
stopSenderThread(alsoJoin = true);
}
Best regards,
-- David
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]