NullPointerException jdk Logger caused

We usually call the JDK log to log, will be used to get a logger,
 Logger logger = Logger.getLogger("xxxx");  


Logger's log method calls after.
    public void log(Level level, String msg) {
if (level.intValue() < levelValue || levelValue == offValue) {
return;
}
LogRecord lr = new LogRecord(level, msg);
doLog(lr);
}

But details have not been concerned. In fact, while the inner is LogRecord logger for recording information, which is a sequence of the class, use can be transmitted in a manner RMI.
Today, in dealing with a problem NullPointerException generation. The root cause is logger.log () method of our own code called when the logging, but passed a logRecord to log method, this is his new Record out, pass the level and the difference between Log information to log in using such methods in that the value of the attribute assigned doLog Logger class will logRecord method of loggerName the like,
  private void doLog(LogRecord lr) {
lr.setLoggerName(name);
String ebname = getEffectiveResourceBundleName();
if (ebname != null) {
lr.setResourceBundleName(ebname);
lr.setResourceBundle(findResourceBundle(ebname));
}
log(lr);
}

And our own new out logRecord simply call the constructor, and did not give them loggerName property assignment are null, the need to distinguish between the different modules of information according to LoggerName display the log in the back, this time to perform equals calls loggerNmae The method will result in a NullPointerException.
Published 56 original articles · won praise 0 · Views 7794

Guess you like

Origin blog.csdn.net/chainhou/article/details/84412077