Logger LOG = Loggerfactory.getlogger () __ehcache

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.