1 23 24 28 29 package com.sun.enterprise.admin.selfmanagement.event; 30 31 import javax.management.NotificationFilter ; 32 import java.util.List ; 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 import java.util.StringTokenizer ; 36 import java.util.logging.Level ; 37 import java.util.logging.LogRecord ; 38 import com.sun.appserv.management.ext.logging.*; 39 import com.sun.appserv.management.base.Util; 40 import com.sun.enterprise.util.i18n.StringManager; 41 42 50 public class LogEventFilter implements NotificationFilter { 51 private static StringManager sm = StringManager.getManager(LogEventFilter.class); 52 private boolean anyLogger = false; 53 54 private ArrayList <String > loggerNames; 55 56 private Level level; 57 58 59 public LogEventFilter() { 60 } 61 62 public List getLoggerNames() { 63 return loggerNames; 64 } 65 66 public void setLoggerNames(String loggers) { 67 if( loggers == null ){ 68 return; 69 } 70 loggerNames = new ArrayList <String >( ); 71 StringTokenizer tokenizer = new StringTokenizer (loggers, ","); 72 while( tokenizer.hasMoreTokens()) { 73 String loggerName = tokenizer.nextToken(); 74 if ("*".equals(loggerName)) { 75 anyLogger = true; 76 loggerNames.add( loggerName ); 77 return; 78 } 79 loggerNames.add( loggerName ); 80 } 81 } 82 83 public String getLevel() { 84 return level.toString(); 85 } 86 87 public void setLevel(String level) { 88 this.level = Level.parse(level); 89 } 90 91 96 public boolean isNotificationEnabled( 97 javax.management.Notification notification ) { 98 boolean loggerNameMatched = false; 99 boolean logLevelMatched = false; 100 101 if (anyLogger) 102 loggerNameMatched = true; 103 else { 104 String loggerNameFromNotification = (String )Util.getAMXNotificationValue(notification, 105 LogRecordEmitter.LOG_RECORD_LOGGER_NAME_KEY); 106 Iterator iterator = loggerNames.iterator( ); 107 while( iterator.hasNext( ) ) { 108 String loggerNameFromList = (String ) iterator.next( ); 109 if( loggerNameFromNotification.startsWith( loggerNameFromList )) { 110 loggerNameMatched = true; 111 break; 112 } 113 } 114 } 115 Level logLevelFromNotification = (Level )Util.getAMXNotificationValue(notification, 116 LogRecordEmitter.LOG_RECORD_LEVEL_KEY); 117 if( logLevelFromNotification.intValue() >= this.level.intValue() ) { 118 logLevelMatched = true; 119 } 120 return loggerNameMatched && logLevelMatched; 121 } 122 123 124 } 125 | Popular Tags |