01: /**
02: * Copyright (C) 2002
03: */package org.objectweb.util.monolog;
04:
05: import org.objectweb.util.monolog.api.LoggerFactory;
06: import org.objectweb.util.monolog.api.HandlerFactory;
07: import org.objectweb.util.monolog.api.LevelFactory;
08: import org.objectweb.util.monolog.api.Logger;
09: import org.objectweb.util.monolog.api.BasicLevel;
10: import org.objectweb.util.monolog.file.monolog.PropertiesConfAccess;
11: import org.objectweb.util.monolog.wrapper.common.Configurable;
12:
13: import java.util.Properties;
14: import java.io.FileInputStream;
15:
16: /**
17: * This class checks if it possible to use two LoggerFactory instances
18: * @author Sebastien Chassande-Barrioz
19: */
20: public class TestMultipleLoggerFactory {
21:
22: public static void main(String[] args) {
23: if (args.length < 4) {
24: System.out.println("Usage: TestMultipleLoggerFactory "
25: + "<logger factory class name A> "
26: + "<properties file name A> "
27: + "<logger factory class name B> "
28: + "<properties file name B> " + "<order: A | B> ");
29: System.exit(1);
30: }
31: LoggerFactory lfa = null;
32: LoggerFactory lfb = null;
33: try {
34: lfa = (LoggerFactory) Class.forName(args[0]).newInstance();
35: lfb = (LoggerFactory) Class.forName(args[2]).newInstance();
36:
37: Properties pa = new Properties();
38: pa.load(new FileInputStream(args[1]));
39:
40: Properties pb = new Properties();
41: pb.load(new FileInputStream(args[3]));
42:
43: if (args.length == 5 && args[4].equalsIgnoreCase("b")) {
44: PropertiesConfAccess.load(pa, lfa,
45: (HandlerFactory) lfa, (LevelFactory) lfa);
46:
47: ((Configurable) lfb).configure(pb);
48: } else {
49: PropertiesConfAccess.load(pa, lfa,
50: (HandlerFactory) lfa, (LevelFactory) lfa);
51:
52: ((Configurable) lfb).configure(pb);
53: }
54:
55: } catch (Exception e) {
56: e.printStackTrace();
57: System.exit(1);
58: }
59:
60: Logger la = lfa.getLogger("a");
61: Logger lb = lfa.getLogger("b");
62: la.log(BasicLevel.WARN, "Message 1 send by the logger A");
63: la.log(BasicLevel.WARN, "Message 2 send by the logger A");
64: la.log(BasicLevel.WARN, "Message 3 send by the logger A");
65: lb.log(BasicLevel.WARN, "Message 1 send by the logger B");
66: lb.log(BasicLevel.WARN, "Message 2 send by the logger B");
67: lb.log(BasicLevel.WARN, "Message 3 send by the logger B");
68: la = lfa.getLogger("a.c");
69: la.log(BasicLevel.WARN, "Message 1 send by the logger A.C");
70: la.log(BasicLevel.WARN, "Message 2 send by the logger A.C");
71: la.log(BasicLevel.WARN, "Message 3 send by the logger A.C");
72: lb = lfa.getLogger("b.d");
73: lb.log(BasicLevel.WARN, "Message 1 send by the logger B.D");
74: lb.log(BasicLevel.WARN, "Message 2 send by the logger B.D");
75: lb.log(BasicLevel.WARN, "Message 3 send by the logger B.D");
76: }
77:
78: }
|