In the Java class java.util.logging.Logger, what is the difference between the global and the root loggers? Are they the same?
No they are not the same.
public static void main(String[] args) throws Exception {
System.out.println(Logger.getLogger(""));
System.out.println(Logger.getGlobal());
System.out.println(Logger.getGlobal().getParent());
}
Will for example output:
java.util.logging.LogManager$RootLogger@27082746
java.util.logging.Logger@66133adc
java.util.logging.LogManager$RootLogger@27082746
As you can see, the root logger is the parent of the global logger. The root logger is used to propagate levels to child loggers and is used hold the handlers that can capture all published log records. The global logger is just a named logger that has been reserved for causal use. It is the System.out
of the logging framework, so use it only for throw away code.
Logger::getLogger with an empty string for the name argument, does this return the global logger or the root logger?
It returns the root logger.