On Nov 28, 2005, at 6:28 PM, Trenton D. Adams wrote:
I can't see using anything other than the root logger. Can you? Am I missing something?


I have 3 reasons for using loggers other than the root logger:

1.  Differential logging levels.
In both development, and in production, it is sometimes useful to increase the logging verbosity for specific classes and packages. We do this to help identify where problems are originating. In Production especially, this is an important tool because we can't put the production applications into debug to trace through the code and determine where a problem originates.


2.  Many applications running under a single JVM.
Our company uses webMethods. webMethods has a piss-poor logging architecture but fortunately it is a Java-based middle-ware server.

To get better logging granularity, I created a log4j wrapper service within webMethods.

Because all our webMethods projects run under a single webMethods server which runs under a single JVM, we create separate appender/ logger pairs for each project. The appenders identify the separate log files for each project, and the loggers specify the package starting point for each project and allow each project to have separate log levels that are relevant to that project's needs.

In our webMethods environment, we use the root logger as a default logger for our common services and for those projects that do not properly create their project-specific logger.

This is a basic paradigm which should work for any environment where many disparate applications must run under a single JVM.


3.  Specialized logging.
The MyJXTA2 project (http://myjxta2.jxta.org/) is an Open Source chat program built on the JXTA networking infrastructure. In MyJXTA2 there is the general logger defined by the root logger and various appenders that may be used for File, Console or XML output. Then, there is a specialized Chat Log Appender. This appender has a filter used to specify only the Chat text (no other trace, debug, info, warning or error info is captured by this appender). This appender creates a stripped-down log message which does not contain most of the "normal" logging information (e.g., class name, logging level, MDC, NDC, etc.).

There is a separate MyJXTA2 Chat Logger that specifies the single Class that processes all the chat text and the info level that is used by this class when logging chat text. No matter what kind of level is being spcified for the root logger, this separate logger ensures that we can always have a chat log.


So, yes. There are reasons for using loggers other than the root logger.


Mike McAngus

Reply via email to