Bug 41670 - Allow to flush a given Logger or Appender or all of them
Summary: Allow to flush a given Logger or Appender or all of them
Status: RESOLVED LATER
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.3alpha
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-21 11:29 UTC by olivier dupuy
Modified: 2007-08-22 19:57 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description olivier dupuy 2007-02-21 11:29:39 UTC
Hi,

See my post #15 in the bug 28647
As indicated in the reply #16, it makes more sense to make this an RFE of its 
own so here it is
http://issues.apache.org/bugzilla/show_bug.cgi?id=28647

I totally aggree with the flushing being tied to the level of the event (as in 
28647). This totally makes sense and would be good to have it in the default 
log4J.

My use cases for a flush of a given Logger, of one Appender or of all the 
Logger/Appender are the following
1) application shuting down. You don't want to loose any logging done so far
2) need to see the whole log in production (or in a production like 
environment) from an administrative interface or not without penaly for the 
normal performance (so you just flush for this purpose). So you need a way to 
force a flush of one or all Logger/Appender

As Simon in 28647, I also use a shutdown hook in my application to address the 
issue in case 1) The only way that I found to flush was to close all the 
appenders. This is fine as I am stopping the application but a way to flush 
globally all the logs without closing the appenders in a very simple way should 
also be there. But what do I know about other libraries/jars outside of my 
code ? They could also use Log4J and log something after this closing 
operation. Closing the appenders could forbid them to log normally and would 
create confusing error messages about closed appenders. A simple way to flush 
would be very convenient.

Case 2). I am simply stuck. I don't want to close all the appenders to reopen 
them later (if I can). I could loose some logging in the mean time and create 
some serious mess. So flushing should be present in each appender that could 
delegate to sub appenders if required. Here I am totally stuck with the default 
implementation. I want to use out of the box functions of log4j without 
creating my own appenders and others

The current implementation looks like the app runs forever or never needs to be 
maintained/troubleshooted but this is not always the case in real life.

Regarding the API, I am proposing a method
- Logger.flush() (not static) sends a flush order to all the appenders this 
logger is connected to
- Appender.flush() (not static) sends a flush order to all this appender 
(implementation) and sub appenders if any
- Logger.flushAll() (static) and/or Appender.flushAll() (static) sends a flush 
order to all the opened appenders
I insist on the fact that you may want flushing a Logger or/and an Appender (or 
all) based on your situation. 

Implementation.
Guys you are the specialists. You could add these methods, create an interface 
FlushableLogger/Appender with the new methods to preserve the compatibility, 
decide to create a new kind of LoggingEvent forcing a flush.... It's up to you

Thanks a lot for this great library.

Olivier DUPUY
Comment 1 Curt Arnold 2007-08-22 19:57:38 UTC
log4j 2.0 design goal.