package somepackage;Thoughts?
import java.util.logging.Logger;
/**
* Self maintaining package level logger access
*
*/
final class Log {
private static Logger logger;
// not thread safe
static Logger getLogger() {
if (logger == null) {
logger =
Logger.getLogger(Log.class.getPackage().getName());
}
return logger;
}
private Log(){}
}
Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts
Friday, August 29, 2008
Self maintaining package level logger access class
Many times I have seen that programmers declare a static field which hold an instance of a Logger. I find this pattern repeated in many classes in the same package. Below is an example of a simple package level logger accessor class. It has an interesting property being a self maintaining code in that you can drop this code in any package and fix the package name by hand or even better let the IDE such as Eclipse provide the quick fix to correct the package for you.
Subscribe to:
Posts (Atom)