1 18 19 import org.objectweb.util.monolog.api.MonologFactory; 20 21 import java.util.Properties ; 22 23 27 public class SpecificConf { 28 29 public static void main(String [] 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 MonologFactory lf = null; 39 try { 40 lf = (MonologFactory) Class.forName(args[0]).newInstance(); 41 } catch (ClassCastException e) { 42 throw new ClassCastException ( 43 "The specified class is not a Logger factory: " + args[0]); 44 } catch (Exception e) { 45 throw new ClassCastException ( 46 "Logger factory class is not availlable: " + args[0]); 47 } 48 49 String mode = (args.length>1 ? args[1] : null); 50 Properties prop = null; 51 if (mode != null && !mode.equalsIgnoreCase("null")) { 52 String configFileName = (args.length>2 ? args[2] : null); 53 prop = new Properties (); 54 prop.put(MonologFactory.LOG_CONFIGURATION_TYPE, mode); 55 if (configFileName != null) { 56 prop.put(MonologFactory.LOG_CONFIGURATION_FILE, configFileName); 57 } 58 59 String 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 try { 67 lf.configure(prop); 68 } catch (Exception 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 |