import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyClass { private static final Log LOG = LogFactory.getLog(MyClass.class); public void doSomething() { LOG.debug("Doing something..."); } }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.BasicConfigurator; public class MyClass { static { BasicConfigurator.configure(); } private static final Log LOG = LogFactory.getLog(MyClass.class); public void doSomething() { LOG.debug("Doing something..."); } }In both examples, we use the LogFactory.getLog() method to obtain a Log instance for a specified class. This allows us to use a consistent logging interface across multiple logging frameworks. The package library used in these examples is org.apache.commons.logging.