Why do you consider it troubling to have a log field in all classes where you want to do logging?
posted 13 years ago
Originally posted by Ulf Dittmer: Why do you consider it troubling to have a log field in all classes where you want to do logging?
I really find it better to create a wrapper class for the Logger and declare some static methods to be accessed directly from the methods, rather than creating a Logger object in each class. I believe the old fashin is a bit messy, that's why I decided to create the wrapper.
Did you realize that java.util.logging package uses the same (old-fashioned) style as log4j?
Using the wrapper class will mean you lose some of the features of log4j. log4j can include location information in the output; the documentation (see PatternLayout) warns about the performance impacts of including that information so you probably would not use it on a regular basis, but it might be helpful to track down a problem. With your setup the location information would point to your wrapper class.
Using the wrapper class only to pass in the class does sound better than your other idea to get the class name out of the stack trace.
Get me the mayor's office! I need to tell him about this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop