This discussion is archived
4 Replies Latest reply: Dec 2, 2010 1:18 PM by 820683 RSS

Problem with logging not working with handlers

820683 Newbie
Currently Being Moderated
I have a wierd problem with logging and maybe someone here can point me in the correct direction to look. I install a custom FileHandler for various loggers. This has been working for a few years. Now it no longer works. Nothing ends up in the log file although it is created.

What I have narrowed it down to is a change in the JVM. If I run application under JDK 1.6.0_05 (what I had in production), this works. If I run the application under JDK 1.6.0_22, it does not work. This is on Solaris 10 and the only change that I make is to change the symbolic link "latest" in "/usr/jdk" to one JDK release or the other. It is reproducable 100% of the time. Use the old JDK and it works, use the new JDK and it does not.

I am at a loss as to what might be wrong.

Here is the relevant code that sets up the handler and associates it with the logger:

Logger l = Logger.getLogger(loggerName);
if (null != level) {
l.setLevel(level);
}
System.out.println("logger level is " + l.getLevel());
if (null != useParentHandlers) {
l.setUseParentHandlers(useParentHandlers);
}
String loggerPattern = logDir + pattern;
Handler h = new FileHandler(loggerPattern, limit, count, append);
h.setLevel(Level.ALL);
Formatter f = new UniformLogFormatter();
h.setFormatter(f);
l.addHandler(h);
logger.info("Added FileHandler[" + loggerPattern + ", " + limit + ", " + count + ", " + append + "] for logger: " + loggerName);
l.info("log file opened");

I see the "log file opened" but never see any other log message within. The "server.log" does see the messages, however.

Any help will be greatly appreciated.

Brett
  • 1. Re: Problem with logging not working with handlers
    jtahlborn Expert
    Currently Being Moderated
    At some point in time, the internals of the LogManager/Logger classes were changed so that they maintain WeakReferences to child Loggers. my guess is that your code is not keeping a hard reference to the Logger which you have configured and it is getting garbage collected at some later point in time (and therefore not getting any future messages).
  • 2. Re: Problem with logging not working with handlers
    820683 Newbie
    Currently Being Moderated
    Did some more debugging. The application is an application running under the Glassfish 2.1.1 application server. The logger is configured in a Lifecycle module and accessed in an EJB module. Here is what I found.

    With JDK 1.6.0_05, the logger that I get in the Lifecycle module is the same logger instance that I get within the EJB where I am logging. In the EJB, I get all of the handlers and print out the information and all is correct and the logging works with the handler.

    Change the symbolic link to point to JDK 1.6.0_22 and the logger that I get in the Lifecycle module is not the same logger instance that I get within the EJB where I am logging. This time in the EJB, the logger's level is "null" and there is no handler associated with the logger. So that is why it is not logging. What I don't understand is why the logger instance is retrieved in the EJB is not the same logger instance in the Lifecycle module.

    Any ideas will be greatly appreciated.
  • 3. Re: Problem with logging not working with handlers
    820683 Newbie
    Currently Being Moderated
    Okay, that is starting to make some sense. I can quickly test that. I saw your response just after I posted new information. Very helpful. I'm going to change the code to keep a reference and try it. Thanks!

    Brett

    PS. Any idea where I could find that information about the change?
  • 4. Re: Problem with logging not working with handlers
    820683 Newbie
    Currently Being Moderated
    This was the problem. All better now.

    Thanks.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points