1 4 5 package org.objectweb.util.monolog; 6 7 import org.objectweb.util.monolog.api.LoggerFactory; 8 import org.objectweb.util.monolog.api.HandlerFactory; 9 import org.objectweb.util.monolog.api.LevelFactory; 10 import org.objectweb.util.monolog.api.Logger; 11 import org.objectweb.util.monolog.api.BasicLevel; 12 import org.objectweb.util.monolog.file.monolog.PropertiesConfAccess; 13 import org.objectweb.util.monolog.wrapper.common.Configurable; 14 15 import java.util.Properties ; 16 import java.io.FileInputStream ; 17 18 22 public class TestMultipleLoggerFactory { 23 24 public static void main(String [] args) { 25 if (args.length<4) { 26 System.out.println("Usage: TestMultipleLoggerFactory " 27 + "<logger factory class name A> " 28 + "<properties file name A> " 29 + "<logger factory class name B> " 30 + "<properties file name B> " 31 + "<order: A | B> "); 32 System.exit(1); 33 } 34 LoggerFactory lfa = null; 35 LoggerFactory lfb = null; 36 try { 37 lfa = (LoggerFactory) Class.forName(args[0]).newInstance(); 38 lfb = (LoggerFactory) Class.forName(args[2]).newInstance(); 39 40 Properties pa = new Properties (); 41 pa.load( new FileInputStream (args[1]) ); 42 43 Properties pb = new Properties (); 44 pb.load( new FileInputStream (args[3]) ); 45 46 if (args.length == 5 && args[4].equalsIgnoreCase("b") ) { 47 PropertiesConfAccess.load(pa, 48 lfa, (HandlerFactory) lfa, (LevelFactory) lfa); 49 50 ((Configurable) lfb).configure(pb); 51 } 52 else { 53 PropertiesConfAccess.load(pa, 54 lfa, (HandlerFactory) lfa, (LevelFactory) lfa); 55 56 ((Configurable) lfb).configure(pb); 57 } 58 59 } 60 catch (Exception e) { 61 e.printStackTrace(); 62 System.exit(1); 63 } 64 65 Logger la = lfa.getLogger("a"); 66 Logger lb = lfa.getLogger("b"); 67 la.log(BasicLevel.WARN, "Message 1 send by the logger A"); 68 la.log(BasicLevel.WARN, "Message 2 send by the logger A"); 69 la.log(BasicLevel.WARN, "Message 3 send by the logger A"); 70 lb.log(BasicLevel.WARN, "Message 1 send by the logger B"); 71 lb.log(BasicLevel.WARN, "Message 2 send by the logger B"); 72 lb.log(BasicLevel.WARN, "Message 3 send by the logger B"); 73 la = lfa.getLogger("a.c"); 74 la.log(BasicLevel.WARN, "Message 1 send by the logger A.C"); 75 la.log(BasicLevel.WARN, "Message 2 send by the logger A.C"); 76 la.log(BasicLevel.WARN, "Message 3 send by the logger A.C"); 77 lb = lfa.getLogger("b.d"); 78 lb.log(BasicLevel.WARN, "Message 1 send by the logger B.D"); 79 lb.log(BasicLevel.WARN, "Message 2 send by the logger B.D"); 80 lb.log(BasicLevel.WARN, "Message 3 send by the logger B.D"); 81 } 82 83 84 } 85 | Popular Tags |