![]() ![]() This is done using the Category's logging methods: debug(), info(), warn(), error(), and fatal(), which map one-to-one with the defined Priorities described previously. Messages are logged based upon their priority. If a category is not assigned a priority, it inherits its category from its closest ancestor with an assigned priority.Ī Category must contain a Priority level, either explicitly, by naming the Priority in the Category definition, or implicitly, through inheritance. The set of possible priorities are DEBUG, INFO, WARN, ERROR, and FATAL. Priorities are assigned to Categories to determine which log messages to actually log. You can now log messages using any of the logging methods described in the next section. This statement creates an instance of a Category that can be used to log messages based on the previous Category definition. The DEBUG and console values associated with this Category define the priority level of this Category and the name of the Appender to use when logging a message, respectively.Ĭategories are referenced by name, and so to access the previous Category definition you would call the static Category.getInstance() method with the name of the Category: static Category cat = Category.getInstance("chapter11.Log4JApp") This statement defines a Category named chapter11.Log4JApp that logs all messages with a priority of DEBUG or higher to the console of the running application. An example definition of a Category doing just this is contained in the following code snippet: 4JApp= DEBUG, console An example of this would be a Category that logged all "debug" statements to the Appender defined in the previous section. This name is the Category name that can be loaded and used to log messages. They allow developers to define how and when a log statement should be executed and then assign this definition a case-sensitive name that it can be referenced by. CategoriesĬategories are the heart of Log4J. In the next section, we close the loop by assigning the Appender to a Category. These lines together define an Appender named console that outputs all of its messages in the format defined by the SimpleLayout object to the application console. The third line of this snippet assigns the Layout class to the console Appender. ![]() The second line defines an Appender named console that uses the, which does just as it sounds and logs all messages to the application console. We need to focus on the second and third lines of this snippet. (It is discussed in the following section.) =Īs you examine the previous snippet, you should ignore the first line. This is done using a code snippet similar to the following: 4JApp= DEBUG, console The most common way to leverage an Appender is to assign it a Layout and then assign it to a Category. Appenders allow logging requests to be printed to multiple output destinations such as consoles, files, NT event loggers, and many others. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |