1 7 8 package java.util.logging; 9 10 import java.util.Enumeration ; 11 import java.util.List ; 12 import java.util.ArrayList ; 13 import sun.management.MXBeanSupport; 14 15 31 class Logging extends MXBeanSupport implements LoggingMXBean { 32 33 private static LogManager logManager = LogManager.getLogManager(); 34 35 38 Logging() { 39 super(LoggingMXBean .class); 40 } 41 42 public List <String > getLoggerNames() { 43 Enumeration loggers = logManager.getLoggerNames(); 44 ArrayList <String > array = new ArrayList <String >(); 45 46 for (; loggers.hasMoreElements();) { 47 array.add((String ) loggers.nextElement()); 48 } 49 return array; 50 } 51 52 private static String EMPTY_STRING = ""; 53 public String getLoggerLevel(String loggerName) { 54 Logger l = logManager.getLogger(loggerName); 55 if (l == null) { 56 return null; 57 } 58 59 Level level = l.getLevel(); 60 if (level == null) { 61 return EMPTY_STRING; 62 } else { 63 return level.getName(); 64 } 65 } 66 67 public void setLoggerLevel(String loggerName, String levelName) { 68 if (loggerName == null) { 69 throw new NullPointerException ("loggerName is null"); 70 } 71 72 Logger logger = logManager.getLogger(loggerName); 73 74 if (logger == null) { 75 throw new IllegalArgumentException ("Logger " + loggerName + 76 "does not exist"); 77 } 78 79 Level level = null; 80 if (levelName != null) { 81 level = Level.parse(levelName); 83 } 84 85 logger.setLevel(level); 86 } 87 88 public String getParentLoggerName( String loggerName ) { 89 Logger l = logManager.getLogger( loggerName ); 90 if (l == null) { 91 return null; 92 } 93 94 Logger p = l.getParent(); 95 if (p == null) { 96 return EMPTY_STRING; 98 } else { 99 return p.getName(); 100 } 101 } 102 103 } 104 | Popular Tags |