import org.apache.log4j.Logger; public class MyClass { final static Logger logger = Logger.getLogger(MyClass.class); public static void main(String[] args) { logger.debug("This is a debug message"); } }
import org.apache.log4j.Logger; public class MyClass { final static Logger logger = Logger.getLogger(MyClass.class); public void myMethod() { logger.debug("Entering myMethod..."); // Some code here logger.debug("Leaving myMethod..."); } }In the above example, we have used the debug() method to log messages at the beginning and end of a method. This can be helpful in debugging the application and understanding the flow of control. The package library for org.apache.log4j is log4j-1.2.17.jar.