1 16 17 package examples.lf5.UsingSocketAppenders; 18 19 import org.apache.log4j.Logger; 20 import org.apache.log4j.PropertyConfigurator; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 25 41 42 44 public class UsingSocketAppenders { 45 49 53 57 private static Logger logger1 = 58 Logger.getLogger(UsingSocketAppenders.class); 59 private static Logger logger2 = 60 Logger.getLogger("TestClass.Subclass"); 61 private static Logger logger3 = 62 Logger.getLogger("TestClass.Subclass.Subclass"); 63 67 71 public static void main(String argv[]) { 72 String resource = 74 "/examples/lf5/UsingSocketAppenders/socketclient.properties"; 75 URL configFileResource = 76 UsingSocketAppenders.class.getResource(resource); 77 PropertyConfigurator.configure(configFileResource); 78 79 logger1.debug("Hello, my name is Homer Simpson."); 81 logger1.debug("Hello, my name is Lisa Simpson."); 82 logger2.debug("Hello, my name is Marge Simpson."); 83 logger2.debug("Hello, my name is Bart Simpson."); 84 logger3.debug("Hello, my name is Maggie Simpson."); 85 86 logger2.info("We are the Simpsons!"); 87 logger2.info("Mmmmmm .... Chocolate."); 88 logger3.info("Homer likes chocolate"); 89 logger3.info("Doh!"); 90 logger3.info("We are the Simpsons!"); 91 92 logger1.warn("Bart: I am through with working! Working is for chumps!" + 93 "Homer: Son, I'm proud of you. I was twice your age before " + 94 "I figured that out."); 95 logger1.warn("Mmm...forbidden donut."); 96 logger1.warn("D'oh! A deer! A female deer!"); 97 logger1.warn("Truly, yours is a butt that won't quit." + 98 "- Bart, writing as Woodrow to Ms. Krabappel."); 99 100 logger2.error("Dear Baby, Welcome to Dumpsville. Population: you."); 101 logger2.error("Dear Baby, Welcome to Dumpsville. Population: you.", 102 new IOException ("Dumpsville, USA")); 103 logger3.error("Mr. Hutz, are you aware you're not wearing pants?"); 104 logger3.error("Mr. Hutz, are you aware you're not wearing pants?", 105 new IllegalStateException ("Error !!")); 106 107 108 logger3.fatal("Eep."); 109 110 logger3.fatal("Mmm...forbidden donut.", 111 new SecurityException ("Fatal Exception ... ")); 112 113 logger3.fatal("D'oh! A deer! A female deer!"); 114 logger2.fatal("Mmmmmm .... Chocolate.", 115 new SecurityException ("Fatal Exception")); 116 117 try { 122 Thread.currentThread().sleep(5000); 123 } catch (InterruptedException ie) { 124 } 125 126 } 127 128 132 136 140 } 141 | Popular Tags |