Java 17 Recipes
Download 3.2 Mb. Pdf ko'rish
|
Java 17 Recipes
How It Works
To control the size of log files, configure the java.util.logging framework and specify rolling log files. Choosing the rolling log files option causes the latest information to be kept in LogApplication0.log. Progressively older information is in LogApplication1 .log, LogApplication2.log, and so forth. When LogApplication0.log fills to the limit you specify (50,000 bytes in this example), its name is rotated to LogApplicationLog1 .log, and the other files have their names similarly rotated downward. The number of log files to maintain is determined by the java.util.logging.FileHandler.count property, which is set to 4 in this recipe’s example. The FileHandler configuration Chapter 9 exCeptions and Logging 349 parameter to distinguish rotated logs is "%g" (a generation number). If it is not specified in the properties file, and the count is greater than 1 (4 in this recipe), the generation number is added to the end of the file name—after a dot. The logging.properties file begins by defining the handlers that the java.util .logging framework use. Handlers are objects that take care of logging messages. FileHandler is specified in the recipe, which logs messages to files. Next, the logging levels are defined. Within a logging framework, there is the concept of separate logger objects. A logger can carry different configurations (for example, different logging levels) and be identified in the log file. The example configures the recipeLogger’s level to info. In contrast, the root logger’s level is ALL (root loggers in the java.util.logging framework are denoted by no prefix before the property). On the other side, OFF disables logging. The next section of the logging.properties file defines the FileHandler configuration. The formatter indicates how the log information is written to disk. The simpleFormatter writes the information as plain text, with a line indicating the date and time, a line with the logging level, and the message to be logged. Following the formatter, the FileHandler pattern is defined. This specifies the file name and location of the log files (the %g is replaced by the rolling log number [0 ~ 3]). The Limit property defines how many bytes the log can have before rolling over (50,000 bytes ~ 50kb). The count defines the maximum index of log files to keep (in this recipe’s case, 4). Download 3.2 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling