This is an improvement (good), but it can be improved a bit.
Set the final flags for each logging level (FINE, etc.) in the global object used as the configuration, then use StringBuffer to create your debug output - you can even format numbers into a stream at the same time.
public class MyAppConfig {
public final boolean FINE=true;
}
public class MyApp {
void someFunction() {
...
int imagesProcessed;
imagesProcessed = processImages();
if (MyAppConfig.FINE) logger.fine(new StringBuffer(35).
append("Count of images processed: ").append(imagesProcessed).toString());
...
}
}
Here, the string buffer is configured with an "initial capacity" of 35 characters. If you know how many characters will be created, you can specify hints for StringBuffer.
source
share