Over a million developers have joined DZone.

Class Rename Friendly Log Instance

·
Use the following to automatically use the current class name for the log category (example is for commons-logging, works with log4j, too):


class Foo {
   private final Log log = LogFactory.getLog(getClass());
}


Compare to the following where the class name is refered to explicitely. If the class is renamed or parts of the codes are copied ("reused") the logging will by misleading.


class Foo {
   private static final Log log = LogFactory.getLog(Foo.class);
}



Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}