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 Steve Ebersole <st...@austin.rr.com> on 2001/12/30 21:55:06 UTC

Clearing loggers from the Hierarchy's internal hash table

Is there a way to clear logger entries from the Hierarchy class's internal
Hashtable?

The issue I am trying to get around deals with the way in which I am
creating loggers for my User object.  The Logger is an instance variable and
is created by: Logger.getLogger( "session." + user + "_" + session ).  The
combination username plus HTTP session id will be pretty unique.  After
looking through the code for LogManager, DefaultLoggerRepository, and
Hierarchy I have seen no place where the loggers are ever cleaned up (once
called they remain in the hierarchy's hashtable, thus preventing garbage
collection).  I am afraid these log4j loggers will in essence become a
memory-leak, "clearable" only when the VM is shutdown.

I understand that in the normal course/usage of log4j this is excatly what
you probably want to happen.  But in my scenario, it can potentially be
pretty detrimental.

Is there something I missed; someway to clear an individual entry from this
hashtable?

If not, looks like I'll have to subclass or edit Hierarchy to add a
removeLogger method.  What additional clean-up type methods should I call on
the Logger in that case?
Logger.removeAllAppenders()?
Any others?

Thanks,
Steve


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Clearing loggers from the Hierarchy's internal hash table

Posted by Scott Farquhar <sc...@atlassian.com>.
One possible method is to use a weakHashMap.  That way when there are no 
more class references to the object, it will be cleared up.

I haven't looked at the code, so I may be off base here.

WeakHashMap:
   http://java.sun.com/j2se/1.3/docs/api/java/util/WeakHashMap.html

Cheers,
Scott

-- 
Scott Farquhar :: scott@atlassian.com

Atlassian :: http://www.atlassian.com
      Supporting YOUR J2EE World


Steve Ebersole wrote:

> Is there a way to clear logger entries from the Hierarchy class's internal
> Hashtable?
> 
> The issue I am trying to get around deals with the way in which I am
> creating loggers for my User object.  The Logger is an instance variable and
> is created by: Logger.getLogger( "session." + user + "_" + session ).  The
> combination username plus HTTP session id will be pretty unique.  After
> looking through the code for LogManager, DefaultLoggerRepository, and
> Hierarchy I have seen no place where the loggers are ever cleaned up (once
> called they remain in the hierarchy's hashtable, thus preventing garbage
> collection).  I am afraid these log4j loggers will in essence become a
> memory-leak, "clearable" only when the VM is shutdown.
> 
> I understand that in the normal course/usage of log4j this is excatly what
> you probably want to happen.  But in my scenario, it can potentially be
> pretty detrimental.
> 
> Is there something I missed; someway to clear an individual entry from this
> hashtable?
> 
> If not, looks like I'll have to subclass or edit Hierarchy to add a
> removeLogger method.  What additional clean-up type methods should I call on
> the Logger in that case?
> Logger.removeAllAppenders()?
> Any others?
> 
> Thanks,
> Steve
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Clearing loggers from the Hierarchy's internal hash table

Posted by Ceki Gulcu <ce...@qos.ch>.
At 14:55 30.12.2001 -0600, you wrote:
>Is there a way to clear logger entries from the Hierarchy class's internal
>Hashtable?
>
>The issue I am trying to get around deals with the way in which I am
>creating loggers for my User object.  The Logger is an instance variable and
>is created by: Logger.getLogger( "session." + user + "_" + session ).  The
>combination username plus HTTP session id will be pretty unique.  After
>looking through the code for LogManager, DefaultLoggerRepository, and
>Hierarchy I have seen no place where the loggers are ever cleaned up (once
>called they remain in the hierarchy's hashtable, thus preventing garbage
>collection).  I am afraid these log4j loggers will in essence become a
>memory-leak, "clearable" only when the VM is shutdown.
>
>I understand that in the normal course/usage of log4j this is excatly what
>you probably want to happen.  But in my scenario, it can potentially be
>pretty detrimental.
>
>Is there something I missed; someway to clear an individual entry from this
>hashtable?
>
>If not, looks like I'll have to subclass or edit Hierarchy to add a
>removeLogger method.  

Steve,

Removing the logger from the hashtable is the easier part. You also have to link the children of the removed category with its nearest ancestor. 

You would also need to close the appenders of the removed logger but that's something that should be done before removing the logger not necessarily within the remove method. 

Regards, Ceki

>What additional clean-up type methods should I call on
>the Logger in that case?
>Logger.removeAllAppenders()?
>Any others?
>
>Thanks,
>Steve


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>