LogManagement.java

00001 
00026 package org.objectweb.jonas.common;
00027 
00028 import java.util.Properties;
00029 import java.util.TreeSet;
00030 
00031 import javax.ejb.EJBException;
00032 
00033 import org.objectweb.jonas.management.ReconfigDispatcher;
00034 import org.objectweb.jonas.management.ReconfiguredProp;
00035 import org.objectweb.util.monolog.api.Logger;
00036 import org.objectweb.util.monolog.api.Level;
00037 
00038 public class LogManagement extends ReconfigDispatcher implements LogManagementMBean {
00039 
00040     // Value used as sequence number by reconfiguration notifications
00041     long sequenceNumber = 0;
00042 
00043     // Name as used to label configuration properties
00044     public static final String SERVICE_NAME = "log";
00048     private static LogManagement unique = null;
00049 
00050     public static LogManagement getInstance() {
00051         if (unique == null) {
00052             unique = new LogManagement();
00053         }
00054         return unique;
00055     }
00056 
00061     public String [] getTopics() {
00062         Logger[] logs = Log.getLoggerFactory().getLoggers();
00063         // put names in alphabetical order
00064         TreeSet tset = new TreeSet();
00065         for (int i = 0; i < logs.length; i++) {
00066             tset.add(logs[i].getName());
00067         }
00068         return (String []) tset.toArray(new String [0]);
00069     }
00070 
00074     public String getTopicLevel(String topic) {
00075         String ret = null;
00076         Logger topicLogger = Log.getLoggerFactory().getLogger(topic);
00077         Level lev = topicLogger.getCurrentLevel();
00078         return lev.getName();
00079     }
00080 
00084     public void setTopicLevel(String topic, String level) {
00085         Logger topicLogger = Log.getLoggerFactory().getLogger(topic);
00086         Level lev = Log.getLevelFactory().getLevel(level);
00087         // must check null (bug monolog)
00088         if (lev != null) {
00089             topicLogger.setLevel(lev);
00090         } else {
00091             throw new EJBException("Unknown level " + level);
00092         }
00093         // the modified property name is 'logger.topic.level'
00094         String propName = "logger." + topic + ".level";
00095         // Send a notification containing the new value of this property to the listner MBean
00096         sendReconfigNotification(++sequenceNumber, SERVICE_NAME, new ReconfiguredProp(propName, level));
00097     }
00098 
00102     public Properties getProperties() {
00103         Properties props = Log.getProperties();
00104         if (props == null) {
00105             Log.getLoggerFactory();
00106             props = Log.getProperties();
00107         }
00108         return props;
00109     }
00110 
00111     public void saveConfig() {
00112         // Send save reconfig notification
00113         sendSaveNotification(++sequenceNumber, SERVICE_NAME);
00114     }
00115 
00116 }

Generated on Tue Feb 15 15:05:14 2005 for JOnAS by  doxygen 1.3.9.1