[fedora-java] Re: [jonas-team] Monolog on gcj

Vadim Nasardinov vadimn at redhat.com
Fri Aug 19 14:59:33 UTC 2005


On Thursday 18 August 2005 18:07, Florent BENOIT wrote:
> I applied the change (+ some doc) in the current CVS head of
> Monolog.

The patch is a tad suboptimal.

http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/monolog/monolog/src/org/objectweb/util/monolog/wrapper/javaLog/LoggerFactory.java.diff?r1=1.12&r2=1.13


The reason java.util.logging.LogManager only keeps weak references to
the loggers it manages is in order to avoid a resource leak.  If the
application chooses not to retain a hard reference to a logger, then
the LogManager should not prevent the unneeded logger from getting
GC-ed.  Makes sense.

The exact same logic applies to Monolog's LoggerFactory.  It should
not keep hard references to loggers it creates.  It is up to the
calling application to retain a reference if the app wishes to avoid
the cost of creating a new logger instance every time it needs one.

Where does that leave us?  Andrew ran into the above problem in an old
version of Carol.  Recent versions do not have this problem for the
simple reason that Carol no longer uses Monolog.  It's been
Monolog-free since March 15 (good job, Florent!):

  http://www.objectweb.org/wws/arc/carol-commits/2005-03/msg00078.html

However, if we want to patch Monolog for those remaining parts of
Jonas that continue to depend on it, then someone should take a closer
look at whether or not the following class should be responsible for
retaining hard references to loggers it creates:

  org.objectweb.util.monolog.file.monolog.PropertiesConfAccess

This responsibility should most certainly not be born by the
LoggerFactory class.



> Andrew Haley wrote:
...
> > Logger getLogger(String name)
> >
> > but LogManagers only keep weak references to their logs.  So, as
> > soon as a log has been created you need to keep a hard reference
> > to it.
> >
> > In Monolog there is
> > org.objectweb.util.monolog.wrapper.javaLog.LoggerFactory, and that
> > uses a LogManager to keep track of the instances of Logger it
> > creates.
...
> >--- src/org/objectweb/util/monolog/wrapper/javaLog/LoggerFactory.java~
> >+++ src/org/objectweb/util/monolog/wrapper/javaLog/LoggerFactory.java
> >@@ -45,6 +45,8 @@
> >         */
> >        protected static Logger rootLogger = null;
> > 
> >+  private ArrayList loggers = new ArrayList();
> >+
> >     /**
> >      * This static code initialize the value of the variable defined into
> >      * BasicLevel.
> >@@ -145,6 +147,7 @@
> >         if (o == null) {
> >             // It doesn't exist => creates and adds it
> >             Logger result = new Logger(name, resName);
> >+           loggers.add(result);
> >             Monolog.debug("Instanciate the logger " + name);
> >             manager.addLogger(result);
> >             return result;




More information about the java-devel mailing list