The Logger,appender and layout of Logback

Source: Internet
Author: User

Logback is built on top of three main classes: Logger,appender and layout. These three components work together to enable developers to record messages by message type and level, and to control the output format and output destination of messages during the program's run time.

The logger class is part of the Logback-classic module, and the Appender and layout interfaces come from Logback-core. As a multipurpose module, Logback-core does not contain any logger.

1. Logger context

In Logback-classic, each logger is linked to a loggercontext,loggercontext responsible for manufacturing logger, and is responsible for arranging the logger in a tree structure. The logger is a named entity. Their names are case sensitive and follow the hierarchical naming conventions: If the name of the logger is prefixed with the name of another logger, then the former is called the ancestor of the latter. If there is no other ancestor between logger and its descendants logger, then the former is called the father of the child logger. The root logger is at the top of the logger level, and what is special about it is that it is the common ancestor of each level. Like all other logger, the root logger can be obtained by its name, as follows:

Logger Rootlogger = Loggerfactory.getlogger (Org.slf4j.Logger.ROOT_LOGGER_NAME);

All other logger are also obtained by GetLogger the static method of the Org.slf4j.LoggerFactory class. The GetLogger method is called a parameter with the logger name.

2. Level of validity level inheritance

Logger can be assigned a level. The levels are: Trace,debug,info,warn and error, defined in the Ch.qos.logback.classic.Level class. Note that in Logback, the level class is final and cannot be inherited, and the marker object provides a more flexible approach.

If the logger is not assigned a level, it inherits from the nearest ancestor with the assigned level. More formally: The effective level of logger L is equal to the first non-null level of its hierarchy, in order from L onwards up to root logger. To ensure that all logger can eventually inherit a level, the root logger always has a level, by default, this level is debug.


Not yet finished ... .....-.......................... ....... ..... .................. .........


The Logger,appender and layout of Logback

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.