import org.apache.log4j.Logger; public class MyClass { private static final Logger logger = Logger.getLogger(MyClass.class); public void doSomething() { if (logger.isInfoEnabled()) { logger.info("Doing something..."); } // do something else } }
import org.apache.log4j.Logger; public class MyApp { private static final Logger logger = Logger.getLogger(MyApp.class); public static void main(String[] args) { logger.debug("Debugging message"); logger.info("Informational message"); logger.warn("Warning message"); logger.error("Error message"); logger.fatal("Fatal message"); } }In this example, the Logger is used to log messages at different levels: debug, info, warn, error, and fatal. The appropriate configuration is necessary for these messages to be logged to their respective destinations. In summary, the org.apache.log4j package provides a versatile logging library for Java applications. The Logger.isInfoEnabled() method can be used to check if the logging level is set to INFO and conditionally log messages.