LOG4J2 (category and logger)

Source: Internet
Author: User
Tags deprecated log4j

Excerpt from official documentation: that is, logger is a subclass of category, with more functions than the parent class

Logger is a subclass of category, i.e. it extends category. In the other words, a loggeris a category. Thus, all operations The can is performed on a category can is performed on a logger. Internally, whenever log4j is asked to produce a Category object, it'll instead produce a Logger object. LOG4J 1.2 willnever produce Category objects but Onlylogger instances. In order to preserve backward compatibility, methods this previously accepted category objects still continue to accept CA Tegory objects.

For example, the following is all legal and would work as expected.

    Deprecated form:
    Category cat = category.getinstance ("foo.bar")

    //Preferred form for retrieving loggers:
    Logger Logger = Logger.getlogger ("Foo.bar")
   

The first form is deprecated and should are avoided.

There is absolutely no need for new client code to use or refer to Thecategory class. Whenever possible, please avoid referring to it or using it.

Configure the root logger with the following syntax: 0

Log4j.rootlogger   =   [  level  ]  ,   Appendername, &nbs P Appendername,   ...

where level   is the priority of logging, divided into off, FATAL, ERROR, WARN, INFO, DEBUG, all, or custom levels. LOG4J recommends using only four levels, with the priority from high to low being error, WARN, INFO, DEBUG. By defining the level here, you can control the switch to the appropriate level of log information in your application. For example, if the info level is defined here, the log information for all debug levels in the application will not be printed.   Appendername is where you specify where the log information is exported. Multiple output destinations can be specified at the same time.
Log4j.rootcategory=debug,   stdout,r

That means I'm going to show all the priorities equal to and higher than DEBUG information.
in the log4j.properties file, "Log4j.rootcategory=debug,stdout,r" is rewritten as "Log4j.rootcategory=off,   Stdout,r", This will not display all of the log information, and resolves the issues raised in this article.
in the log4j.properties file, "Log4j.rootcategory=debug,stdout,r" is rewritten as "log4j.rootcategory=info,   Stdout,r", This displays only the log information for info,   WARN,   error, and debug information is not displayed;

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.