You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Leo Lima <on...@l3o.net> on 2006/09/29 15:35:28 UTC

KeyFileAppender not closing filehandlers

Hello all. I am quite new to log4j, so please bear with me if I am on the 
wrong track. Any feedback is welcome!

I found the KeyFileAppender from Yoav Shapira, Steve Ebersole in the net and 
I was very happy with it.
So I started using it on my transaction server, using the transaction code 
as a key and had all my transaction logging in files. I was really happy, 
then.
But now, periodically, I have to shut down the server because the server (a 
JBoss 4.0.4) keeps (if not all) a lot of open filehandlers, from past 
transactions.
I need to solve this problem and I stumble on some problems. The transaction 
does finish, and then I could close the logfile handler. How do I tell the 
logger to close it? I thought about adding a new method to KeyFileAppender, 
and the transact manager (which is my code) would have to cast the appender 
that I get from the logger and make it close that given key, something like:

public void closeKeyFile(String key) {
    QuietWriter writer = (QuietWriter)writers.get(key);
    if (writer == null) return;
    try {
        writer.write( super.layout.getFooter() );
        if (super.immediateFlush)
            writer.flush();
        writer.close();
    }
    catch(IOException e) {
        LogLog.error("Could not close " + writer, e);
    }
}

Is that correct? I fear that isn't ok, I don't know. Maybe there's a newer 
KeyFileAppender somewhere that I don't know? Could you please tell?
And, if I must implement that, I have one doubt. If I have to restart the 
transaction, a new Writer will be created? I think so, but...?

Another idea would be to 'timeout' a writer, but that would require period 
checks somewhere in the logging system. Where do I put them? I really don't 
know, and I don't like the idea of creating a new thread

Thanks in advance,
Leo. 




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: KeyFileAppender not closing filehandlers

Posted by Jacob Kjome <ho...@visi.com>.
I'm not actually sure what the KeyfileApender is, but you should 
always do this for a ServletContextListener shutdown event..

LogManager.shutdown();


Jake

At 08:35 AM 9/29/2006, you wrote:
 >Hello all. I am quite new to log4j, so please bear with me if I am on the
 >wrong track. Any feedback is welcome!
 >
 >I found the KeyFileAppender from Yoav Shapira, Steve Ebersole in the net and
 >I was very happy with it.
 >So I started using it on my transaction server, using the transaction code
 >as a key and had all my transaction logging in files. I was really happy,
 >then.
 >But now, periodically, I have to shut down the server because the server (a
 >JBoss 4.0.4) keeps (if not all) a lot of open filehandlers, from past
 >transactions.
 >I need to solve this problem and I stumble on some problems. The transaction
 >does finish, and then I could close the logfile handler. How do I tell the
 >logger to close it? I thought about adding a new method to KeyFileAppender,
 >and the transact manager (which is my code) would have to cast the appender
 >that I get from the logger and make it close that given key, something like:
 >
 >public void closeKeyFile(String key) {
 >    QuietWriter writer = (QuietWriter)writers.get(key);
 >    if (writer == null) return;
 >    try {
 >        writer.write( super.layout.getFooter() );
 >        if (super.immediateFlush)
 >            writer.flush();
 >        writer.close();
 >    }
 >    catch(IOException e) {
 >        LogLog.error("Could not close " + writer, e);
 >    }
 >}
 >
 >Is that correct? I fear that isn't ok, I don't know. Maybe there's a newer
 >KeyFileAppender somewhere that I don't know? Could you please tell?
 >And, if I must implement that, I have one doubt. If I have to restart the
 >transaction, a new Writer will be created? I think so, but...?
 >
 >Another idea would be to 'timeout' a writer, but that would require period
 >checks somewhere in the logging system. Where do I put them? I really don't
 >know, and I don't like the idea of creating a new thread
 >
 >Thanks in advance,
 >Leo.
 >
 >
 >
 >
 >---------------------------------------------------------------------
 >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
 >For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org