1 28 29 package org.objectweb.util.trace; 30 31 32 import java.util.HashMap ; 33 import java.util.Map ; 34 import java.util.Properties ; 35 36 import org.objectweb.util.monolog.api.HandlerFactory; 37 import org.objectweb.util.monolog.api.LevelFactory; 38 import org.objectweb.util.monolog.api.LoggerFactory; 39 import org.objectweb.util.monolog.file.monolog.PropertiesConfAccess; 40 41 42 43 54 public class TraceSystem 55 { 56 57 protected static final String prefix = "org.objectweb.util"; 58 59 60 protected static Map list_ = new HashMap (); 61 62 63 protected static String level_ = "default"; 64 65 70 protected static LoggerFactory getLoggerFactory() { 71 Properties props = new Properties (); 72 try { 73 props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(level_+".properties")); 74 } catch (Exception e) { 75 System.err.println("Configuration file for log not found. Traces are disabled: " + e); 76 return null; 77 } 78 79 String lfClassName = props.getProperty("log.config.classname", null); 81 if (lfClassName == null) { 82 System.err.println("Malformed log configuration file: log.config.classname not available"); 83 } 84 85 try { 86 LoggerFactory lf = (LoggerFactory) Class.forName(lfClassName).newInstance(); 87 PropertiesConfAccess.load(props, lf, (HandlerFactory) lf, (LevelFactory) lf); 89 return lf; 90 } catch (Exception e) { 91 System.err.println("Logs are disabled:" + e); 92 } 93 94 return null; 95 } 96 97 102 protected static void create(String logger) { 103 list_.put(logger, 104 new TraceTemplate(getLoggerFactory().getLogger(prefix+"."+logger))); 105 } 106 107 112 public static void setLevel(String level) { 113 level_ = level; 114 } 115 116 121 public static Trace get(String id) { 122 if (!list_.containsKey(id)) 123 create(id); 124 return (Trace) list_.get(id); 125 } 126 } 127 | Popular Tags |