Now that we have a logging solution in place, i think it is time to
write down some logging guidelines. I have looked at the Geronimo
logging guidelines, part of the coding standards:
(http://wiki.apache.org/geronimo/CodingStandards)
The first question is how to obtain the logger. Is it simply:
public class MyClass {
Logger logger = Logger.getLogger(MyClass.class.getName());
}
The next question is which log levels to use for what. j.u.l has the
following log levels built in:
SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST
Comparing with the Geronimo logging levels,
SEVERE corresponds to FATAL
nothing corresponds to ERROR
WARNING corresponds to WARN
INFO corresponds to INFO
CONFIG corresponds to nothing
FINE corresponds to DEBUG
FINER corresponds to TRACE
FINEST corresponds to nothing
I suppose messages that would be ERRORs in Geronimo will become WARNINGs
in Yoko? Apart from that we should probably stick to the Geronimo coding
standards.
In Geronimo, it is suggested to do verbose logging like this:
if (logTrace) {
log.trace("About to do stuff " + stuff);
}
This avoids unneccessary string concatenation, which would potentially
hurt performance.
In j.u.l, this becomes:
if(logger.isLoggable(Level.FINER) {
log.finer("About to do stuff " + stuff);
}
I personally don't like this style very well. Wouldn't it be an idea to
create a log utility object and do something like this:
LogUtil.log(logger, Level.FINER, "About to do stuff " + stuff);
or perhaps even
LogUtil.logFiner(logger, "About to do stuff " + stuff);
Any comments or ideas?
Regards,
Anders