8.6.3 Guidelines for creating and setting loggers and handlers
The following are the guidelines for creating and setting loggers and handlers:
-
You can connect multiple file handlers for one logger. However, you cannot connect to the file handlers, having the same output destination, from multiple loggers.
-
If you want to change the output destination of log for each application, create a logger for each application.
-
A logger can have hierarchical relationship. If a logger has hierarchical relationship, the log messages acquired by a lower level logger are propagated to an upper level logger. Stop the propagation of a logger as and when required. Particularly, a root logger exists by default at the top of the logger. In the case of the J2SE default settings, ConsoleHandler is connected to the root logger. If you do not stop the propagation to the upper level logger, all messages are output to the console from ConsoleHandler of the root logger.
-
The handler outputs messages for each instance, and therefore if one output message is sent to multiple handlers, the output message is output multiple times. For example, the ConsoleHandler messages of two locations are output twice to the console.
-
If you are using multiple log files in one application, create a handler for each output destination.
The following figure shows an example of creating loggers and handlers.
In this example, two types of loggers (com.example.userlogger1 and com.example.userlogger2) are created for J2EE applications 1 and 2. To output two types of log files from com.example.userlogger1 depending on the output levels and the output contents of the log, two types of the CJMessageFileHandler handlers (conf1 and conf2) are created. With this configuration, you can output important user logs on and above the SEVERE level to the log file 1, and all the user logs on and above the INFO level to the log file 2. On the other hand, only one type of log file is output from com.example.userlogger2. In such cases, of all the logs specified from a J2EE application, the user logs that are up to the level specified in the logger of com.example.userlogger2 and the conf3 handler are output to the log file 3. If you want to output the log to the console, use the ConsoleHandler handler of the standard J2SE.
Set up the size and number of files of log files appropriately depending on the user log quantity, which is output by applications, and the specified output level.