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 someMethod() { // do something log.fatal("Something went wrong!"); } }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.Logger; public class MyClass { private static final Log log = LogFactory.getLog(MyClass.class); public void someMethod() { // do something Logger.getLogger(MyClass.class).fatal("Something went wrong!"); } }In this example, we use Log4j as the logging implementation instead of the default. We create a static instance of Log for the MyClass class and log a fatal-level message using Log4j's Logger class. Package library: org.apache.commons.logging.