KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SpecificConf


1 /**
2  * Copyright (C) 2001-2003 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 import org.objectweb.util.monolog.api.MonologFactory;
20
21 import java.util.Properties JavaDoc;
22
23 /**
24  *
25  * @author Sebastien Chassande-Barrioz
26  */

27 public class SpecificConf {
28
29     public static void main(String JavaDoc[] args) {
30         if (args.length < 1) {
31             System.out.println("Syntax error !");
32             System.out.println(
33                 "java SpecificConf <logger factory class name> <mode> "
34                 + "[<config file name> [ true | false ]]");
35             System.exit(1);
36         }
37         // Instanciate the logger factory
38
MonologFactory lf = null;
39         try {
40             lf = (MonologFactory) Class.forName(args[0]).newInstance();
41         } catch (ClassCastException JavaDoc e) {
42             throw new ClassCastException JavaDoc(
43                 "The specified class is not a Logger factory: " + args[0]);
44         } catch (Exception JavaDoc e) {
45             throw new ClassCastException JavaDoc(
46                 "Logger factory class is not availlable: " + args[0]);
47         }
48
49         String JavaDoc mode = (args.length>1 ? args[1] : null);
50         Properties JavaDoc prop = null;
51         if (mode != null && !mode.equalsIgnoreCase("null")) {
52             String JavaDoc configFileName = (args.length>2 ? args[2] : null);
53             prop = new Properties JavaDoc();
54             prop.put(MonologFactory.LOG_CONFIGURATION_TYPE, mode);
55             if (configFileName != null) {
56                 prop.put(MonologFactory.LOG_CONFIGURATION_FILE, configFileName);
57             }
58
59             String JavaDoc useClassPath = (args.length>3 ? args[3] : null);
60             if (useClassPath != null) {
61                 prop.put(MonologFactory.LOG_CONFIGURATION_FILE_USE_CLASSPATH,
62                     useClassPath);
63             }
64         }
65         //load the configuration
66
try {
67             lf.configure(prop);
68         } catch (Exception JavaDoc e) {
69             System.out.println("Impossible to configure in " + mode + " mode: "
70                 + e.getMessage());
71             System.exit(1);
72         }
73
74         Simple sc = new Simple(lf);
75         sc.foo();
76         sc.bar();
77     }
78 }
Popular Tags