import org.apache.log4j.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class); public void myMethod() { LOGGER.info("This is an informational message"); } }
import org.apache.log4j.Logger; public class MyClass { private static final Logger LOGGER = Logger.getLogger(MyClass.class); public void myMethod() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("This is a debug message"); } } }This example shows how to log a debug message only when debug mode is enabled. The isDebugEnabled() method is used to check whether debug mode is enabled before logging the message. Overall, the org.apache.log4j Logger info method allows developers to log informational messages in their Java programs. The package is part of the Apache Log4j project, a popular logging framework for Java.