By the name of logger can know the meaning of this sentence is to use the Logger factory to obtain logger instance, but do not understand the principle, looked at the source code:
The GetLogger method in Loggerfactory returns an instance of a static binding named after name, which is typically named after the class in which the logger instance is located, such as through the class name. Class.getname () obtained.
public static Logger GetLogger (String name) {
Iloggerfactory iloggerfactory = Getiloggerfactory ();
return Iloggerfactory.getlogger (name);
Iloggerfactory interface Instances bind loggerfactory internally at compile time, only one public Logger GetLogger (String name) method in this interface, returning the appropriate instance based on the parameter name
Look at this getiloggerfactory () method
public static Iloggerfactory Getiloggerfactory () {
if (initialization_state = = uninitialized) {
initialization _state = ongoing_initialization;
Performinitialization ();
}
Switch (initialization_state) {case
successful_initialization: Return
Staticloggerbinder.getsingleton (). Getloggerfactory ();
Case Nop_fallback_initialization: Return
nop_fallback_factory;
Case Failed_initialization:
throw new IllegalStateException (unsuccessful_init_msg);
Case ongoing_initialization:
//Support re-entrant behavior.
Also http://bugzilla.slf4j.org/show_bug.cgi?id=106 return
temp_factory;
}
throw new IllegalStateException ("Unreachable Code");
}
It is clear that this is an instance of the return iloggerfactory used to fetch the GetLogger method. In the logger interface, the method of logging output is specified, and the output log information can be seen in the console according to the corresponding parameters.