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:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}