while many applications will only deal with a single logger instance, it may make sense for some applications to have multiple loggers. an example of this is a job scheduling server that creates a separate log file for each task (see figure 1). to split log messages between files, the server assigns a new logger instance when the task is created. the result is a much cleaner separation of events - something that can be invaluable when tracing a problem.
to obtain a logger instance, we need a unique name. keep in mind that loggers exist for the life of the application, so its very important to choose a unique name. failure to do so can result in strange or unexpected behavior. since class names must be unique, a common solution is to use the primary class name. thus a logger for the class com.example.myserver might be obtained via the following code:
logger logger = logger.getlogger("com.example.myserver");
log records explained 【推荐阅读:ClassLoader介绍】
anyone who has dealt with complex enterprise applications knows the value of a good logging solution. features such as consolidating log files, separating events, and turning debugging on or off all come free with a good logging api. as a result, developers have been converting their existing system.out logging to many of the advanced solutions that have appeared on the java scene.
this article attempts to demonstrate how to convert your system.out logging to the new java 1.4 logging apis. along the way, new concepts and algorithms will be introduced to solve common interoperability issues.
using the 1.4 logger api
sending a message is a little different than printing to an outputstream. each logging message needs to contain... 下一页