import org.apache.log4j.Logger; public class MyClass { private static final Logger log = Logger.getLogger(MyClass.class); public void myMethod() { log.debug("This is a debug message."); log.info("This is an info message."); log.warn("This is a warning message."); log.error("This is an error message."); log.fatal("This is a fatal message."); } }
import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; public class MyApp { private static final Logger log = Logger.getLogger(MyApp.class); public static void main(String[] args) { BasicConfigurator.configure(); log.debug("Hello, log4j!"); } }This example shows how to configure the logger using `BasicConfigurator` and how to record a log message. The `Logger.getLogger()` method is used to obtain a logger instance for `MyApp`. Package library: `org.apache.log4j`