1 16 package examples.lf5.InitUsingDefaultConfigurator; 17 18 import org.apache.log4j.Logger; 19 import org.apache.log4j.NDC; 20 import org.apache.log4j.lf5.DefaultLF5Configurator; 21 22 import java.io.IOException ; 23 24 34 35 37 public class InitUsingDefaultConfigurator { 38 42 46 private static Logger logger = 50 Logger.getLogger(InitUsingDefaultConfigurator.class); 51 52 56 60 public static void main(String [] args) throws IOException { 61 DefaultLF5Configurator.configure(); 64 65 NDC.push("#23856"); 67 for (int i = 0; i < 10; i++) { 69 logger.debug("Hello, my name is Homer Simpson."); 70 logger.info("Mmmmmm .... Chocolate."); 71 logger.warn("Mmm...forbidden donut."); 72 } 73 NDC.pop(); 75 NDC.remove(); 76 77 NDC.push("Another NDC"); 78 logger.fatal("Hello, my name is Bart Simpson."); 80 logger.error("Hi diddly ho good neighbour."); 81 NDC.pop(); 83 NDC.remove(); 84 85 InitUsingDefaultConfigurator.foo(); 87 InnerInitUsingDefaultConfigurator.foo(); 88 89 logger.info("Exiting InitUsingDefaultConfigurator."); 90 91 } 92 93 public static void foo() { 94 logger.debug("Entered foo in InitUsingDefaultConfigurator class"); 95 96 NDC.push("#123456"); 97 logger.debug("Hello, my name is Marge Simpson."); 98 logger.info("D'oh!! A deer! A female deer."); 99 NDC.pop(); 101 NDC.remove(); 102 } 103 104 108 112 116 public static class InnerInitUsingDefaultConfigurator { 117 static Logger logger = 118 Logger.getLogger(InnerInitUsingDefaultConfigurator.class.getName()); 119 120 static void foo() throws IOException { 121 DefaultLF5Configurator.configure(); 125 126 logger.info("Entered foo in InnerInitUsingDefaultConfigurator class."); 127 } 128 } 129 } 130 131 132 133 134 135 | Popular Tags |