1 23 package com.sun.appserv.management.helper; 24 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.Set ; 28 import java.util.HashSet ; 29 30 import java.util.logging.Level ; 31 32 import javax.management.Attribute ; 33 34 import com.sun.appserv.management.ext.logging.Logging; 35 import static com.sun.appserv.management.ext.logging.Logging.*; 36 import com.sun.appserv.management.ext.logging.LogQuery; 37 import com.sun.appserv.management.ext.logging.LogModuleNames; 38 import com.sun.appserv.management.ext.logging.LogQueryResult; 39 import com.sun.appserv.management.ext.logging.LogQueryResultImpl; 40 41 import com.sun.appserv.management.util.misc.GSetUtil; 42 43 44 48 public final class LoggingHelper extends Helper 49 { 50 private final Logging mLogging; 51 52 55 public 56 LoggingHelper( final Logging logging ) 57 { 58 super( logging.getDomainRoot() ); 59 mLogging = logging; 60 } 61 62 public Logging 63 getLogging() 64 { 65 return mLogging; 66 } 67 68 69 76 public LogQueryResult 77 queryServerLog( 78 final String logLevel, 79 final Set <String > modules) 80 { 81 final String name = MOST_RECENT_NAME; 82 final int startIndex = FIRST_RECORD; 83 final boolean searchForward = true; 84 final int maxRecords = ALL_RECORDS; 85 final Long startTime = null; 86 final Long stopTime = null; 87 final List <Attribute > attrs = null; 88 89 assert( getLogging() != null ); 90 91 final LogQueryResult result = getLogging().queryServerLog( 92 name, 93 startIndex, 94 searchForward, 95 maxRecords, 96 startTime, 97 stopTime, 98 logLevel, 99 modules, 100 attrs ); 101 102 return result; 103 } 104 105 111 public LogQueryResult 112 queryServerLog( 113 final String logLevel, 114 final String moduleID) 115 { 116 return queryServerLog( logLevel, GSetUtil.newSet( moduleID ) ); 117 } 118 119 124 public LogQueryResult 125 queryServerLog( final String logLevel ) 126 { 127 return queryServerLog( logLevel, LogModuleNames.ALL_NAMES ); 128 } 129 130 131 135 public LogQueryResult 136 queryAllCurrent() 137 { 138 return queryAllInFile( MOST_RECENT_NAME ); 139 } 140 141 142 143 144 private long 145 now() 146 { 147 return System.currentTimeMillis(); 148 } 149 150 157 public LogQueryResult 158 queryServerLogRecent( final long seconds ) 159 { 160 return queryServerLogRecent( seconds, LogModuleNames.ALL_NAMES ); 161 } 162 163 170 public LogQueryResult 171 queryServerLogRecent( 172 final long seconds, 173 final Set <String > modules ) 174 { 175 final String name = MOST_RECENT_NAME; 176 final int startIndex = LAST_RECORD; 177 final boolean searchForward = false; 178 final int maxRecords = ALL_RECORDS; 179 final Long startTime = now(); 180 final Long stopTime = now() - (seconds * 1000); 181 final List <Attribute > attrs = null; 182 183 final LogQueryResult result = getLogging().queryServerLog( 184 name, 185 startIndex, 186 searchForward, 187 maxRecords, 188 startTime, 189 stopTime, 190 LOWEST_SUPPORTED_QUERY_LEVEL, 191 modules, 192 attrs ); 193 return result; 194 } 195 196 197 201 public LogQueryResult 202 queryAllInFile( final String name ) 203 { 204 final int startIndex = FIRST_RECORD; 205 final boolean searchForward = true; 206 final int maxRecords = ALL_RECORDS; 207 final Long startTime = null; 208 final Long stopTime = null; 209 final List <Attribute > attrs = null; 210 211 final LogQueryResult result = getLogging().queryServerLog( 212 name, 213 startIndex, 214 searchForward, 215 maxRecords, 216 startTime, 217 stopTime, 218 LOWEST_SUPPORTED_QUERY_LEVEL, 219 LogModuleNames.ALL_NAMES, 220 attrs ); 221 222 return result; 223 } 224 225 231 public LogQueryResult[] 232 queryAll() 233 { 234 final String [] names = getLogging().getLogFileNames( SERVER_KEY ); 235 236 final List <LogQueryResult> all = new ArrayList <LogQueryResult>( names.length ); 237 for( final String name : names ) 238 { 239 try 241 { 242 final LogQueryResult result = queryAllInFile( name ); 243 all.add( result ); 244 } 245 catch( Exception e ) 246 { 247 } 249 } 250 251 final LogQueryResult[] results = new LogQueryResultImpl[ all.size() ]; 252 return all.toArray( results ); 253 } 254 } 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | Popular Tags |