Pros and cons for adding a Trace level
Numerous users have asked for the addition of a trace level. This page debates the pros and cons of such a change.
CON
- Many people use INFO and DEBUG for development, eliminating the need for TRACE. One uses DEBUG to output chatty information and INFO to ouput an overview the application's progress.
- The next version of log4j will introduce the concept of domains allowing developers to log by multiple criteria, thus creating a much more powerful way of categorizing (i.e. classifying) logging statements, thus dispensing with the need to use various new levels (e.g. the trace level) to express logging/filtering criteria. With the introduction of domains the trace level will look like what it really is, a common but nonetheless a lame hack.
- It is possible to wrap the Logger class and extend the Level to include support for the trace level.
The complete log4j manual by Ceki Gülcü has a whole chapter discussing extending log4j core classes.
Moreover, The generic <code>log()</code> method in the <code>Logger</code> class takes in a Level as as its first parameter. This allows the developer to log at any level, including the trace level. For example:
{{{ Logger logger = Logger.getLogger("some.logger.name");
- logger.log(XLevel.TRACE, "some message"); }}}
where XLevel class extends the Level class by adding the trace level. There is a section about in the FAQ as well: http://nagoya.apache.org/wiki/apachewiki.cgi?Log4JProjectPages/TraceLevel
Altough typing in this method call is slightly longer than typing the usual printing methods such as <code>logger.debug("message")</code> or <code>logger.info("message")</code>, modern IDEs can easily automate the process.
- A modification to something as central to log4j as the default list of levels must be done with consideration to not damage existing installations which have customized log4j to include TRACE or other custom levels.
PRO
TRACE is a very natural level to use to ouput chatty information during development. It "traces" the program while DEBUG rather gives more of some "overview"-type debugging information.
There is a user-based need for it:
- It is a frequently requested feature as a quick search of the list archives will show.
- The JBoss group actually did extend log4j to add TRACE, and have distributed their server with the extensions included.
- Adding the TRACE level would involve very little effort.
Lack of development levels:
TRACE and DEBUG seems like the two most important development tools. INFO, WARN, ERROR and FATAL are production levels. Thus, if one accepts this point of view, currently log4j offers only one single level dedicated to the development process.
With respect to domains:
Ialready use categories forthe division of different types of log statements. The categories in my system aren't classnames, I make them in a LoggingCategories static file with lots of Strings in them, concatenating each type to form a hierachy of of "domains" if you will. "