1 26 27 package org.objectweb.util.monolog.provider.lib; 28 29 import java.io.FileInputStream ; 30 import java.util.Properties ; 31 import java.util.TreeSet ; 32 33 import org.objectweb.util.monolog.api.BasicLevel; 34 import org.objectweb.util.monolog.api.HandlerFactory; 35 import org.objectweb.util.monolog.api.Level; 36 import org.objectweb.util.monolog.api.LevelFactory; 37 import org.objectweb.util.monolog.api.Logger; 38 import org.objectweb.util.monolog.api.LoggerFactory; 39 import org.objectweb.util.monolog.file.monolog.PropertiesConfAccess; 40 import org.objectweb.util.monolog.provider.api.LoggerProvider; 41 import org.objectweb.util.monolog.provider.lib.topics.BundleTopics; 42 43 44 50 public class LoggerProviderImpl implements LoggerProvider { 51 54 private String configFile = "monolog.CCM.properties"; 55 56 59 private boolean usecp = false; 60 61 64 private LoggerFactory lf = null; 65 66 69 private Properties props = null; 70 71 74 public LoggerProviderImpl() { 75 } 76 77 81 public void configure(String file, boolean useclasspath) { 82 configFile = file; 83 usecp = useclasspath; 84 LoggerFactory lf = getLoggerFactory(); 85 } 86 87 91 public synchronized LoggerFactory getLoggerFactory() { 92 if (lf == null) { 93 try { 94 props = new Properties (); 96 if (usecp) { 97 props.load(ClassLoader.getSystemResourceAsStream(configFile)); 98 } else { 99 props.load(new FileInputStream (configFile)); 100 } 101 String b = props.getProperty("log.config.classname", null); 103 if (b == null) { 104 System.err.println("Malformed configuration log file: log.config.classname not available"); 105 return null; 106 } 107 lf = (LoggerFactory) Class.forName(b).newInstance(); 108 PropertiesConfAccess.load(props, lf, (HandlerFactory) lf, (LevelFactory) lf); 110 } catch (Exception e) { 111 System.err.println("Cannot get LoggerFactory:" + e); 112 e.printStackTrace(); 113 } 114 } 115 return lf; 116 } 117 118 121 public LevelFactory getLevelFactory() { 122 return (LevelFactory) getLoggerFactory(); 123 } 124 125 130 public Logger getLogger(String topic) { 131 return getLoggerFactory().getLogger(topic); 132 } 133 134 137 public Logger getLogger(String topic, Class caller) { 138 String preTopic = TopicProviderSingleton.getTopicProvider().getTopic(caller); 139 getLogger(BundleTopics.getPreTopic("PRETOPIC_OPENCCM_DEFAULT")).log(BasicLevel.DEBUG, 140 "The Topic of " + caller + " is : " + preTopic); 141 return getLoggerFactory().getLogger(preTopic); 142 } 143 144 147 public Logger createLogger(String topic, Class caller, String [] description) { 148 TopicProviderSingleton.createTopic(topic, caller, description); 149 return getLogger(topic, caller); 150 } 151 152 153 157 public String [] getTopics() { 158 Logger[] logs = getLoggerFactory().getLoggers(); 159 TreeSet tset = new TreeSet (); 161 for (int i = 0; i < logs.length; i++) { 162 tset.add(logs[i].getName()); 163 } 164 return (String []) tset.toArray(new String [0]); 165 } 166 167 170 public String getTopicLevel(String topic) { 171 String ret = null; 172 Logger log = getLogger(topic); 173 Level lev = log.getCurrentLevel(); 174 return lev.getName(); 175 } 176 177 180 public void setTopicLevel(String topic, String l) { 181 Logger log = getLogger(topic); 182 Level lev = getLevelFactory().getLevel(l); 183 if (lev != null) { 185 log.setLevel(lev); 186 } else { 187 188 } 189 } 190 191 194 public Properties getProperties() { 195 if (props == null) { 196 getLoggerFactory(); 197 } 198 return props; 199 } 200 201 } 202 | Popular Tags |