I will not mention the name of Log4j. In this regard, this is everything, I am mainly talking about my personal understanding of the core framework of log4j, not involving specific use, the main purpose hopes to help everyone strengthen Log4j Awareness. Due to the limited personal level, improper understanding, I hope that all criticisms are correct, they are afraid.
I. Three types of components: loggers, appenders, and layouts are the basic framework of the LOG4J for basic components of these three class components. Where logger provides the specific functionality of log management (mainly output); appender provides output destinations of log management, ie logs are output to files, or output to consumers, or output to other places; Layout provides the specific format and additional information of the log output, which is simply understood that it is a problem that the output format is typed (similar to Word document).
Second, the relationship between Loggers. Each Logger (root logger exception) is identified by the unique name, which can only generate an instance (Class Static Method) (Class Static Method) (Class Static Method) (Class Static Method) Generate an instance, and the relationship is determined by name. Similar to the inheritance system of the Java class library, all Logger has the same root node, that is, root logger, he can only access Logger.GetrootLogger (Class Static Method), and he will always exist. The relationship between Loggers is shown below (when the inheritance system of the category is more appropriate): [It can't be pasted, if you are interested, find the LIUDONGBAOLLZ ◎ 21cn.com (MSN) Contact Obtain a document in Word format] root logger is All Logger's ancestors, if a logger's name (such as "COM") is another Logger name ("com.sun.java") prefix ("COM" as a separator), then "COM" COM. Sun.java "Ancestral," com.sun.java "is the descendants of COM, which can be understood as" com.sun.java "inheritance (indirect inheritance) in" COM ", everything is just a Java class library that everyone is familiar with system. If a Logger does not have another logger between the Logger with the granddaughter, such as "com" and "com.ibm", there is a parent and child relationship.
Third, the relationship between the Logger level (Level) attribute and the inheritance system. Loggers can be given Level. Levels include: debug, info, warn, error, and fatal, are defined in the org.apache.log4j.Level class. If a Logger does not give any level (Level), he will get the same level (Level) from the nearest ancestor logger. More exactly, the level that Logger (c) can inherit is equal to the first unique rating of the Root Logger from the entire inheritance system from C. To ensure that all Loggers have levels, root logger always gives a level (Level).
Fourth, the relationship between appenders and inheritance system. Logger Additional APPDENDER is attached to you by Method. Any Logger's enabled Logging request forwards the request to all appenders in the higher level of the inheritance system. In other words, Appenders also has additional inheritance characteristics throughout the inheritance system. For example, if a console appender is attached to the root logger, then all enabled Logging requests will be at least in the cosole. If an additional file appender is attached to Logger (C), all Logging requests from the subclasses from C and C are output to File and Console. This feature can be turned off by setting the Additivity Flag to false. (SetAdditivity) to reduce the accumulation of the appender. The rules of this feature (appender additivity) are described as follows: Logger C's log expression output will be passed to all Appenders of C and his Ancestors (ancestor), which is the meaning of "appender additivity". However, if C's Ancestors, called P, the Additivity flag has been set to false, then C's log expression output will pass to C and all the ancestors until P (including P) all Appenders, but does not include any ancestors of P. V. Logging Request and Level (Level) in Logger. The Logging request is done by calling the output method in the Logger, and the main output method has Debug, Info, Warn, Error, Fatal, and Log. Each LogGing request also has a corresponding level, where the logging request level generated by the logGGing request is defined in the parameter, and the level of the LogGing request generated by other methods is determined by the method name, such as Debug. A Logging request is considered to be enabled when its level is above or equal to his logger level, otherwise it is considered disabled. That is, a grade of Q (regardless of whether the level is itself set or obtained by inheritance, the LogGing request for the Logger, which is a colleague), only when P is larger than or equal to Q, will not be enabled. This rule is the core part of the log4j. He assumes that these levels are orderly, for standard grade, Debug