01: package org.objectweb.util.monolog.log4j;
02:
03: import org.objectweb.util.monolog.api.BasicLevel;
04: import org.objectweb.util.monolog.api.Logger;
05: import org.objectweb.util.monolog.api.LoggerFactory;
06: import org.objectweb.util.monolog.wrapper.common.Configurable;
07:
08: import java.util.Properties;
09:
10: public class Config {
11: protected static LoggerFactory factory;
12: protected static String cfgfn;
13:
14: protected static void init() {
15: String loggerFactory = "org.objectweb.util.monolog.wrapper.log4j.MonologLoggerFactory";
16: try {
17: factory = (LoggerFactory) Class.forName(loggerFactory)
18: .newInstance();
19: } catch (Exception exc) {
20: System.err.println("Unable to instantiate monolog wrapper");
21: exc.printStackTrace();
22: System.exit(1);
23: }
24:
25: try {
26: Properties prop = null;
27: /*
28: // Cas 1 --> Ca marche
29: ((Configurable) factory).configure(null);
30: // Cas 2 --> Ca marche
31: prop = new Properties();
32: prop.put(Configurable.LOG_CONFIGURATION_TYPE, Configurable.DEFAULT);
33: ((Configurable) factory).configure(prop);
34: */
35: // Cas 3 ...
36: prop = new Properties();
37: prop.put(Configurable.LOG_CONFIGURATION_TYPE,
38: Configurable.PROPERTY);
39: prop.put(Configurable.LOG_CONFIGURATION_FILE, cfgfn);
40: prop.put(Configurable.LOG_CONFIGURATION_FILE_USE_CLASSPATH,
41: "false");
42:
43: ((Configurable) factory).configure(prop);
44: } catch (Exception exc) {
45: System.err.println("Unable to configure monolog wrapper");
46: exc.printStackTrace();
47: System.exit(-1);
48: }
49: }
50:
51: public static Logger getLogger(String topic) {
52: if (factory == null)
53: init();
54: System.out.println(factory.getLogger(topic).getClass());
55: return (Logger) factory.getLogger(topic);
56: }
57:
58: public static void main(String args[]) {
59: cfgfn = (args.length > 0 ? args[0] : "./debug.cfg");
60: Logger logmon = getLogger("mono");
61: logmon.log(BasicLevel.DEBUG, "ca marche");
62: }
63: }
|