I got an issue which is really baffling me. I wanted to try out some things with the JUL logging (JDK logging). I started out with the following simple program:
package biz.ple;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public class Application {
public static void main(String[] args)
{
Logger logA = LogManager.getLogManager().getLogger("LoggerA");
Logger logB = LogManager.getLogManager().getLogger("LoggerB");
if (logA == null) {
System.out.println("LoggerA is null!");
}
if (logB == null) {
System.out.println("LoggerB is null!");
}
String normalMsg = "Message without cookie prefix.";
String cookieMsg = "[Cookie] Message with a cookie prefix.";
logA.info(normalMsg);
logA.info(cookieMsg);
logB.info(normalMsg);
logB.info(cookieMsg);
}
}
Amazingly, the loggers logA and logB are always null. I read in the documentation that a logger to which the application holds no strong reference my be GCed at any time, but it seems to me that the variables logA and logB are indeed strong references, aren't they?
I really don't understand this and would appreciate any help.
"LoggerA"
elsewhere? My reading of this suggests that this just gets an existing logger, it doesn't create one – Xenophon