1 16 17 package org.apache.log4j.net.test; 18 19 import org.apache.log4j.*; 20 import org.apache.log4j.net.SocketAppender; 21 22 public class Loop { 23 24 public static void main(String [] args) { 25 26 27 Logger root = Logger.getRootLogger(); 28 Logger cat = Logger.getLogger(Loop.class.getName()); 29 30 if(args.length != 2) 31 usage("Wrong number of arguments."); 32 33 String host = args[0]; 34 int port = 0; 35 36 try { 37 port = Integer.valueOf(args[1]).intValue(); 38 } 39 catch (NumberFormatException e) { 40 usage("Argument [" + args[1] + "] is not in proper int form."); 41 } 42 43 SocketAppender sa = new SocketAppender(host, port); 44 Layout layout = new PatternLayout("%5p [%t] %x %c - %m\n"); 45 Appender so = new ConsoleAppender(layout, "System.out"); 46 root.addAppender(sa); 47 root.addAppender(so); 48 49 int i = 0; 50 51 while(true) { 52 NDC.push(""+ (i++)); 53 cat.debug("Debug message."); 54 root.info("Info message."); 55 NDC.pop(); 56 } 57 58 } 59 60 static 61 void usage(String msg) { 62 System.err.println(msg); 63 System.err.println( 64 "Usage: java " +Loop.class.getName() + " host port"); 65 System.exit(1); 66 } 67 68 69 } 70 | Popular Tags |