[fedora-java] Monolog on gcj

Andrew Haley aph at redhat.com
Wed Aug 17 19:00:40 UTC 2005


I've been having a really bizarre time figuring out why on gcj the
trace.properties file of JOnAS doesn't have any effect.  It seems to
be due to weak references.

Java has a class called java.util.logging.LogManager, and you can get
a Logger by calling getLogger:

 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.
So, still no hard references there and it's up to the caller of
LoggerFactory to keep hard references.

JOnAS calls
org.objectweb.util.monolog.file.monolog.PropertiesConfAccess.load(java.util.Properties,
	org.objectweb.util.monolog.api.LoggerFactory,
	org.objectweb.util.monolog.api.HandlerFactory,
	org.objectweb.util.monolog.api.LevelFactory) 
to read the properties file for JOnAS logging, and this routine as a
side-effect creates loggers for all of JOnAS's subsystems.

Later on, TraceCarol does this:

    public static void configure(LoggerFactory lf) {
        carolLogger = lf.getLogger(prefix);

But of course, the LoggerFactory lf only has weak references to its
loggers, so these loggers it created might have disappeared.  This is
why it doesn't matter how I edit the properties files, I get no
output: by the time carol calls getLogger, the logger no longer
exists.

It seems to me that this is a failure of Monolog.  The only way to fix
it is to have Monolog's LoggerFactory keep hard references for its
loggers.

All I have to do to make Monolog work correctly with gcj is add the
patch below.

Andrew.


--- src/org/objectweb/util/monolog/wrapper/javaLog/LoggerFactory.java~  2004-08-17 10:18:08.000000000 +0100
+++ src/org/objectweb/util/monolog/wrapper/javaLog/LoggerFactory.java   2005-08-17 19:25:51.000000000 +0100
@@ -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 fedora-devel-java-list mailing list