KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > log4j > Config


1 package org.objectweb.util.monolog.log4j;
2
3 import org.objectweb.util.monolog.api.BasicLevel;
4 import org.objectweb.util.monolog.api.Logger;
5 import org.objectweb.util.monolog.api.LoggerFactory;
6 import org.objectweb.util.monolog.wrapper.common.Configurable;
7
8 import java.util.Properties JavaDoc;
9
10 public class Config {
11     protected static LoggerFactory factory;
12     protected static String JavaDoc cfgfn;
13
14     protected static void init() {
15         String JavaDoc loggerFactory = "org.objectweb.util.monolog.wrapper.log4j.MonologLoggerFactory";
16         try {
17             factory = (LoggerFactory) Class.forName(loggerFactory).newInstance();
18         }
19         catch (Exception JavaDoc exc) {
20             System.err.println("Unable to instantiate monolog wrapper");
21             exc.printStackTrace();
22             System.exit(1);
23         }
24
25         try {
26             Properties JavaDoc 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 JavaDoc();
37             prop.put(Configurable.LOG_CONFIGURATION_TYPE, Configurable.PROPERTY);
38             prop.put(Configurable.LOG_CONFIGURATION_FILE, cfgfn);
39             prop.put(Configurable.LOG_CONFIGURATION_FILE_USE_CLASSPATH, "false");
40
41             ((Configurable) factory).configure(prop);
42         }
43         catch (Exception JavaDoc exc) {
44             System.err.println("Unable to configure monolog wrapper");
45             exc.printStackTrace();
46             System.exit(-1);
47         }
48     }
49
50     public static Logger getLogger(String JavaDoc topic) {
51         if (factory == null) init();
52         System.out.println(factory.getLogger(topic).getClass());
53         return (Logger) factory.getLogger(topic);
54     }
55
56     public static void main(String JavaDoc args[]) {
57         cfgfn = (args.length > 0 ? args[0] : "./debug.cfg");
58         Logger logmon = getLogger("mono");
59         logmon.log(BasicLevel.DEBUG, "ca marche");
60     }
61 }
62
Popular Tags