import org.apache.log4j.xml.DOMConfigurator; import org.apache.log4j.Category; public class Log4JTest { public static final Category cat = Category.getInstance(Log4JTest.class); public Log4JTest() { DOMConfigurator.configureAndWatch("log4j.xml"); method1(); } public void method1() { method2(); } public void method2() { method3(); } public void method3() { method4(); } public void method4() { Exception e = new Exception("Test Exception"); System.out.println("===============================Output with Log4J==============================="); cat.info(e.toString(), e); System.out.println("==========================Output with e.printStacktrace========================"); e.printStackTrace(); } public static void main(String[] args) { new Log4JTest(); } }