Code example for LogRecord

Methods: setParameters, setSourceClassName, setSourceMethodName, setThrown

0
 
    // Return quickly if no log message will be produced. 
    if (!LOGGER.isLoggable(level))
      return; 
 
    rec = new LogRecord(level, msg);
    if (param != null && param.getClass().isArray())
      rec.setParameters((Object[]) param);
    else 
      rec.setParameters(new Object[] { param });
 
    rec.setThrown(t);
 
    // While java.util.logging can sometimes infer the class and 
    // method of the caller, this automatic inference is not reliable 
    // on highly optimizing VMs. Also, log messages make more sense to 
    // developers when they display a public method in a public class; 
    // otherwise, they might feel tempted to figure out the internals 
    // of ServiceFactory in order to understand the problem. 
    rec.setSourceClassName(ServiceFactory.class.getName());
    rec.setSourceMethodName("lookupProviders");
 
    LOGGER.log(rec);
  } 
}