Log4j Source Code Reading - Log4j Main Class

xiaoxiao2021-03-06  40

First, the main interface of log4j 1, appender: Encapsulates the Appender operation, all appenders should implement the interface. The main methods include: 1), addfiltre (), getfilter (), Clearfilters () Operate the Filter method. 2), Close (): Turn off the appender. 3), doappend (): When the logger wants to print the message, the Appender's DoaPpend () method will be called. 4) GetName (), setName: Settings, get the name of the appender. 5) Geterorhandler (), setErrorhandler (): Set, get an Errorhandler of Appender. 6) GetLayout (), setLayout (): Sets, get layout. 7), RequiresLayout (): Judging whether the appender needs Layout (use). 2, Appendrattachable: Package some of the Appender aggregation, log4j provides the default implementation using AppenderatTachableImpl, and Category implementation is to give all the operational delegate to AppendrattachableImpl. The main methods include: 1), addappender (), removeappender, removeALlappenders, getAppender (), getAltAppenders, etc. 2), isattached (): Judging whether an appender has been loaded into the aggregation. 3, Optionhandler: The method of encapsulating the attribute of the activation setting is an ActivateOptions () method. The settings can be activated by this method, such as generating a file handle according to the set file name. 4, loggerrepository: Package some of the operations of logger aggregation, and the Log4j is used to implement implementation methods. The main methods are: 1), AddhierarchyeventListener (): Using the observer mode to implement an event mechanism. Add observer here. 2), isdisabled (): Judging whether the log of the specified level can be printed. 3), setthreshold (), getthreshold (): Settings, get Threshold level properties. 4) EmitnoaPpenderwarning (): Throw a unusual unusual. 5), getLogger (), getRootLogger (), exists (), getCurrentLoggers (), getCurrentCategories (): Get the Logger. 6), FireAddaPpenderevent (): Trigger the ADD_APPENDER event, calling all the observer's corresponding way, and the FireRemoveAppenderevent () method is also implemented in Hierarchy.

7), RESETCONFIGURATION (): All Logger settings in the aggregate will be default, the RoomLogger level is set to Debug, threshold set bit all. 5, hierarchyeventlistener: Encapsulated the observer's operation. The main methods are: 1), addappenderevent (), removeaPpenderevent (): The entry triggered in two events. 6. RepositorySelector: Only one method getLoggerRepository () getting loggerRepository (). 7, LogRecodfilter: Provides a filtering method Passes (), if you return to True, you will return FALSE. 8, LoggerFactory: Provides a factory approach to creating Logger. This is an abstract factory. Log4j's abstract factory application can learn well, there is a default factory class that needs to use the factory method. If users do not provide their own factory methods, they use their own default factories. 9, ObjectRenderer: Package the parsing method of the object translator Dorender (). The object translator in the log4j reflects a very important point in object-oriented design: "decouple", which "decoupled" to the TOSTRING () method of the object's parsing task, and becomes an object translator, so You can make a class and its interpretation classes can evolve independently. Strong! ! ! ! 10. RENDERSUPPORT: Two methods that enapt the need for supported object translators. GetRendereMap () Gets a renderer's aggregation. Setrenderer () Add an object translator. 11. Configurator: Encapsulated the Configuration Action of the Log4J. Two string regularities, and Doconfigure () methods for actual configuration are provided. But I believe that the design is not really role. 12, Errorhandler: Inherited to the Optionhandler interface. Encapsulated the processing of Error on the appender. 13. ErrorCode: Some constants have been encapsulated so that all classes of this interface are automatically acquired. Although Sun does not agree with this approach, I think this is really convenient. Second, LOG4J's main abstract class 1, layout: implements an OptionHandler interface. It is the basic class of Layout. It provides some constants and methods for Layout. Mainly 1), abstract method format (): Layout Specific parsing method. 2) GetContentType (): Returns the type of content, returns "Text / Plain" by default. 3), getHeader (), getfooter (): Don't know the specific role, returns NULL by default. 4), Ignoresthrowable (): If this Layout does not support throwable, return false. 2, appenderskeleton: implements the Appender, Optionhadler interface. It is the basic class of all appenders.

转载请注明原文地址:https://www.9cbs.com/read-63251.html

New Post(0)