Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Class Rename Friendly Log Instance

DZone's Guide to

Class Rename Friendly Log Instance

·
Free Resource
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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}