Logging in Petstore 2.0 ?

Hi,

In the petstore 2.0 early access https://blueprints.dev.java.net/petstore/index.html, I was looking at the logging. Since the early access code is getting cleaned up and refactored, what conventions and practices should be used for logging?

For example, right now I notice that a lot of code is adding this method

/**

* Method getLogger

* @return Logger - logger for the NodeAgent

*/

public Logger getLogger() {

if (_logger == null) {

_logger=PetstoreUtil.getBaseLogger();

}

return _logger;

}

Its tricky to cut and paste that methofdo nto classes that need logging, so instead, should the petstore logging be reafctored to

1) Inheritence? Make a class PSBaseLogger.java or some utility class with this method and just have the classes that use it *extend* PSBaseLogger so they each have that logger method and so you dont have to paste it everywhere you use the logger?

2) Use utility method? Make a class PSBaseLogger.java or some utility class with this method and just have each method use it. Maybe have a static method to make it easy to use everywhere?

3) other?

What other considerations should be looked at for refactoring the logging?

hth,

Sean

[1279 byte] By [seanbrydona] at [2007-10-3 9:45:52]
# 1

This is not a good candidate for using inheritance since logging is not part of the public API of this class.

However, I would argue that there is no need to do lazy instantiation here. Why not call PetstoreUtil.getBaseLogger() directly everywhere in the app? Makes for cleaner code, and gets rid of the extra member variable _logger.

inder0a at 2007-7-15 5:02:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...