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 ; 9 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).newInstance(); 18 } 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 35 prop = new Properties (); 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 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 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 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 |