import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyClass { private static final Log LOGGER = LogFactory.getLog(MyClass.class); public void doSomething() { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Something is not quite right."); } } }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyOtherClass { private static final Log LOGGER = LogFactory.getLog(MyOtherClass.class); public void doSomethingElse() { String message = "Something else went wrong."; if (LOGGER.isWarnEnabled()) { LOGGER.warn(message, new Exception("Something went wrong.")); } } }In this example, we create a logger for the MyOtherClass class and in the doSomethingElse method, we check if the logger is enabled for warning messages using the isWarnEnabled() method. If it is enabled, we log a warning message and an exception. Package Library: org.apache.commons.logging