1 23 package com.sun.enterprise.server.logging; 24 25 import java.util.Map ; 26 import java.util.Hashtable ; 27 import java.util.Date ; 28 import java.util.Properties ; 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 import java.util.logging.LogManager ; 32 import java.util.logging.LogRecord ; 33 import java.util.logging.Logger ; 34 import java.util.logging.Level ; 35 import java.util.logging.ErrorManager ; 36 import java.util.Enumeration ; 37 import java.util.LinkedList ; 38 import java.util.List ; 39 import java.util.Iterator ; 40 import java.security.*; 41 import java.io.File ; 42 43 import javax.management.Attribute ; 44 import javax.management.AttributeList ; 45 import javax.management.AttributeNotFoundException ; 46 import javax.management.RuntimeOperationsException ; 47 import javax.management.DynamicMBean ; 48 import javax.management.InvalidAttributeValueException ; 49 import javax.management.MBeanException ; 50 import javax.management.MBeanInfo ; 51 import javax.management.MBeanAttributeInfo ; 52 import javax.management.MBeanOperationInfo ; 53 import javax.management.MBeanNotificationInfo ; 54 import javax.management.MBeanParameterInfo ; 55 import javax.management.MBeanServer ; 56 import javax.management.NotificationListener ; 57 import javax.management.NotificationBroadcasterSupport ; 58 import javax.management.ReflectionException ; 59 import javax.management.ObjectName ; 60 import javax.management.OperationsException ; 61 62 import com.sun.enterprise.server.logging.stats.ErrorStatistics; 63 import com.sun.enterprise.server.logging.logviewer.backend.LogFilter; 64 import com.sun.enterprise.server.logging.diagnostics.MessageIdCatalog; 65 66 import com.sun.enterprise.util.StringUtils; 67 import com.sun.enterprise.util.SystemPropertyConstants; 68 69 70 81 public class LogMBean extends NotificationBroadcasterSupport 82 implements DynamicMBean 83 { 84 private static final int MINUTES_TO_MILLISECONDS = 60000; 86 87 private static final String LOGS_DIR = "logs"; 88 89 private ObjectName objectName; 90 91 private LogRotatorSPI accessLogRotator = null; 94 95 private static final String LOG_MBEAN_DESCRIPTION = 96 " Log MBean can be used for Managinging and Monitoring Logs \n" + 97 " The main features provided by this MBean are .... \n" + 98 " 1. Fetch the Loggers available in the server \n" + 99 " 2. Fetch the log level of a given logger \n" + 100 " 3. Dynamically change the log levels of all the avalaible Loggers \n"+ 101 " 4. Send SEVERE and WARNING Log messages as Alarms to all the " + 102 "interested parties "; 103 104 private static final String GET_LOGGER_NAMES = "getLoggerNames"; 105 106 private static final String GET_LOGGER_NAMES_DESCRIPTION = 107 " Gets all the Loggers currently running in the System. The returned "+ 108 " list is not sorted. "; 109 110 private static final String GET_LOGGER_NAMES_UNDER = "getLoggerNamesUnder"; 111 112 private static final String GET_LOGGER_NAMES_UNDER_DESCRIPTION = 113 " Gets all the Loggers under a given logger. The returned list is not "+ 114 " sorted. "; 115 116 private static final String GET_LOG_LEVEL = "getLogLevel"; 117 118 private static final String GET_LOG_LEVEL_DESCRIPTION = 119 " Gets the current Log Level of the given Logger. The 8 Possible " + 120 " values are 1.SEVERE 2.WARNING 3.INFO 4.CONFIG 5.FINE 6.FINER " + 121 " 7.FINEST 8. Null"; 122 123 private static final String SET_LOG_LEVEL = "setLogLevel"; 124 125 private static final String SET_LOG_LEVEL_DESCRIPTION = 126 " Sets the log level of the given logger to the request level. An " + 127 " IllegalArgument Exception will be raised if the level is not one " + 128 " of the following 8 values. 1.SEVERE 2.WARNING 3.INFO 4.CONFIG " + 129 " 5.FINE 6.FINER 7.FINEST 8.OFF"; 130 131 private static final String SET_LOG_LEVEL_FOR_MODULE = 132 "setLogLevelForModule"; 133 134 private static final String SET_LOG_LEVEL_FOR_MODULE_DESCRIPTION = 135 " Sets the log level for a given module .\n" + 136 " The Modules are admin, classloader, cmp-container, configuration "+ 137 " , connector, corba, deployment, ejb-container, javamail, jaxr, " + 138 " jaxrpc, mdb-container, naming, saaj, security, server, " + 139 " transaction, verifier, web-container, core " + 140 " IllegalArgument Exception will be raised if the level is not one " + 141 " of the following 8 values. 1.SEVERE 2.WARNING 3.INFO 4.CONFIG " + 142 " 5.FINE 6.FINER 7.FINEST 8.OFF"; 143 144 private static final String GET_LOG_RECORD_USING_QUERY = 145 "getLogRecordsUsingQuery"; 146 147 private static final String GET_LOG_RECORD_USING_QUERY_DESCRIPTION = 148 " This method returns the Log Records from the server.log file \n"+ 149 " based on the query passed....." ; 150 151 private static final String GET_ARCHIVED_LOG_FILES = 152 "getArchivedLogfiles"; 153 154 private static final String GET_ARCHIVED_LOG_FILES_DESCRIPTION = 155 " This method returns a list of Archived Log files currently " + 156 " available in the domain/log directory"; 157 158 private static final String GET_DIAGNOSTIC_CAUSES_FOR_MESSAGEID = 159 "getDiagnosticCausesForMessageId"; 160 161 private static final String 162 GET_DIAGNOSTIC_CAUSES_FOR_MESSAGEID_DESCRIPTION = 163 " This method returns the Possible Causes for an Error Code specified"; 164 165 private static final String GET_DIAGNOSTIC_CHECKS_FOR_MESSAGEID = 166 "getDiagnosticChecksForMessageId"; 167 168 private static final String 169 GET_DIAGNOSTIC_CHECKS_FOR_MESSAGEID_DESCRIPTION = 170 " This method returns the Diagnostic Checks for an Error Code " + 171 "specified"; 172 173 private static final String GET_DIAGNOSTIC_URI_FOR_MESSAGEID = 174 "getDiagnosticURIForMessageId"; 175 176 private static final String GET_DIAGNOSTIC_URI_FOR_MESSAGEID_DESCRIPTION = 177 " This method returns the URI to locate the latest Diagnostic info " + 178 " on SUN's Docs Website"; 179 180 private static final String ROTATE_NOW = 181 "rotateNow"; 182 183 private static final String ROTATE_NOW_DESCRIPTION = 184 " Log file will be rotated when this method is called, This will " + 185 " override the other two rotation mechanisms of rotation based on " + 186 " log file size or timer.\n The timer will be restarted to schedule " + 187 " next rotation if it is specified."; 188 189 private static final String GET_LOGFILES_DIRECTORY = "getLogFilesDirectory"; 190 191 private static final String GET_ERROR_DISTRIBUTION = "getErrorDistribution"; 192 private static final String GET_ERROR_DISTRIBUTION_DESCRIPTION = ""; 193 194 private static final String GETLOGNAMES4LOGMODULE = "getLognames4LogModule"; 195 private static final String GETLOGNAMES4LOGMODULE_DESCRIPTION = 196 " This method returns the predefined logger names for the module name " + 197 " passed in."; 198 199 private static final String GET_LOGFILES_DIRECTORY_DESCRIPTION = 200 " This method returns the LogFiles Directory to help locate " + 201 " Logfiles in the FileSystem..."; 202 203 private static final String NOTIFICATION_SEVERE_ALARM = 204 "SevereLogMessages"; 205 206 private static final String NOTIFICATION_SEVERE_ALARM_DESCRIPTION = 207 " All Logged Messages whose Log Level is SEVERE will be notified " + 208 " to all the subscribed listeners..." ; 209 210 private static final String NOTIFICATION_WARNING_ALARM = 211 "WarningLogMessages"; 212 213 private static final String NOTIFICATION_WARNING_ALARM_DESCRIPTION = 214 " All Logged Messages whose Log Level is WARNING will be notified " + 215 " to all the subscribed listeners..." ; 216 217 private static final String ATTR_LOGGER_NAMES = "LoggerNames"; 218 219 private static final String ATTR_LOGGER_NAMES_DESCRIPTION = 220 "All the Loggers currently running in the System. The list " + 221 " is not sorted."; 222 223 private static final String ATTR_LOGFILES_DIRECTORY = "LogFilesDirectory"; 224 225 private static final String ATTR_LOGFILES_DIRECTORY_DESCRIPTION = 226 "The LogFiles Directory to help locate " + 227 "Logfiles in the FileSystem..."; 228 229 private static final String ATTR_ARCHIVED_LOG_FILES = "ArchivedLogfiles"; 230 231 private static final String ATTR_ARCHIVED_LOG_FILES_DESCRIPTION = 232 "A list of Archived Log files currently " + 233 "available in the domain/log directory"; 234 235 private static final String ATTR_ERROR_INFORMATION = "ErrorInformation"; 236 private static final String ATTR_ERROR_INFORMATION_DESCRIPTION = 237 "ErrorInformation"; 238 239 private static final String ATTR_KEEP_ERROR_STATISTICS_FOR_HOURS = 240 "KeepErrorStatisticsForHours"; 241 private static final String 242 ATTR_KEEP_ERROR_STATISTICS_FOR_HOURS_DESCRIPTION = 243 "The number of hours for which error statistics are maintained."; 244 245 private static final String ATTR_KEEP_ERROR_STATISTICS_FOR_INTERVALS = 246 "KeepErrorStatisticsForIntervals"; 247 private static final String 248 ATTR_KEEP_ERROR_STATISTICS_FOR_INTERVALS_DESCRIPTION = 249 "Number of intervals for which error statistics are maintained."; 250 251 private static final String ATTR_ERROR_STATISTICS_INTERVAL_DURATION = 252 "ErrorStatisticsIntervalDuration"; 253 private static final String 254 ATTR_ERROR_STATISTICS_INTERVAL_DURATION_DESCRIPTION = 255 "Duration of each interval for which error statistics are retained."; 256 257 private static MBeanOperationInfo [] operationInfoArray = 258 new MBeanOperationInfo [11]; 259 260 private static MBeanAttributeInfo [] attributeInfoArray = 261 new MBeanAttributeInfo [7]; 262 263 266 private static MBeanInfo mBeanInfo; 267 268 private MBeanServer mbeanServer = null; 269 270 private static LogMBean mbeanInstance = null; 271 272 275 public synchronized static LogMBean getInstance( ) { 276 if( mbeanInstance == null ) { 277 mbeanInstance = new LogMBean(); 278 mbeanInstance.initialize( ); 279 } 280 return mbeanInstance; 281 } 282 283 286 private LogMBean( ) { } 287 288 289 public void initialize( ) { 290 291 try { 292 if ( attributeInfoArray.length != 7 ) { 293 throw new RuntimeException ( 294 "attributeInfoArray array is the wrong length" ); 295 } 296 297 attributeInfoArray[0] = new MBeanAttributeInfo ( 298 ATTR_LOGGER_NAMES, "java.util.List", 299 ATTR_LOGGER_NAMES_DESCRIPTION, true, false, false); 300 301 attributeInfoArray[1] = new MBeanAttributeInfo ( 302 ATTR_LOGFILES_DIRECTORY, "String", 303 ATTR_LOGFILES_DIRECTORY_DESCRIPTION, true, false, false); 304 305 attributeInfoArray[2] = new MBeanAttributeInfo ( 306 ATTR_ARCHIVED_LOG_FILES, "[Ljava.lang.String;", 307 ATTR_ARCHIVED_LOG_FILES_DESCRIPTION, true, false, false); 308 309 attributeInfoArray[3] = new MBeanAttributeInfo ( 310 ATTR_ERROR_INFORMATION, List .class.getName(), 311 ATTR_ERROR_INFORMATION_DESCRIPTION, true, false, false); 312 313 attributeInfoArray[4] = new MBeanAttributeInfo ( 314 ATTR_KEEP_ERROR_STATISTICS_FOR_HOURS, int.class.getName(), 315 ATTR_KEEP_ERROR_STATISTICS_FOR_HOURS_DESCRIPTION, 316 true, true, false); 317 318 attributeInfoArray[5] = new MBeanAttributeInfo ( 319 ATTR_KEEP_ERROR_STATISTICS_FOR_INTERVALS, int.class.getName(), 320 ATTR_KEEP_ERROR_STATISTICS_FOR_INTERVALS_DESCRIPTION, 321 true, true, false); 322 323 attributeInfoArray[6] = new MBeanAttributeInfo ( 324 ATTR_ERROR_STATISTICS_INTERVAL_DURATION, long.class.getName(), 325 ATTR_ERROR_STATISTICS_INTERVAL_DURATION_DESCRIPTION, 326 true, true, false); 327 328 MBeanParameterInfo [] loggerNameParam = 329 {new MBeanParameterInfo ("LoggerName", "String", "Logger Name")}; 330 operationInfoArray[0] = new MBeanOperationInfo ( 331 GET_LOGGER_NAMES_UNDER, GET_LOGGER_NAMES_UNDER_DESCRIPTION, 332 loggerNameParam, "java.util.List", MBeanOperationInfo.ACTION); 333 334 operationInfoArray[1] = new MBeanOperationInfo (GET_LOG_LEVEL, 335 GET_LOG_LEVEL_DESCRIPTION, loggerNameParam, "String", 336 MBeanOperationInfo.ACTION); 337 338 MBeanParameterInfo [] loggerNameAndLevelParam = 339 {new MBeanParameterInfo ("LoggerName", "String", "Logger Name"), 340 new MBeanParameterInfo ("LogLevel", "String", "Logger Level") }; 341 operationInfoArray[2] = new MBeanOperationInfo (SET_LOG_LEVEL, 342 SET_LOG_LEVEL_DESCRIPTION, loggerNameAndLevelParam, "void", 343 MBeanOperationInfo.ACTION); 344 345 operationInfoArray[3] = new MBeanOperationInfo ( 346 SET_LOG_LEVEL_FOR_MODULE, SET_LOG_LEVEL_FOR_MODULE_DESCRIPTION, 347 loggerNameAndLevelParam, "void", MBeanOperationInfo.ACTION); 348 349 MBeanParameterInfo [] logviewerQueryParams = 350 {new MBeanParameterInfo ("FileName", "String", 351 " If Filename is specified then it will be used to " + 352 " run the query. If the user specifies null for this " + 353 " argument then the current server.log file will be " + 354 " used to run the query. This argument is specifed to " + 355 " typically run query on Archived Log File "), 356 new MBeanParameterInfo ("FromRecord", "Long", 357 "The location within the LogFile"), 358 new MBeanParameterInfo ("next", "Boolean", 359 "True to get the next set of results and False to get " + 360 " the previous results "), 361 new MBeanParameterInfo ("forward", "Boolean", 362 "True to search forward through the log file " ), 363 new MBeanParameterInfo ("requestedCount", "Integer", 364 "Number of desired records" ), 365 new MBeanParameterInfo ("fromDate", "java.util.Date", 366 " The lower bound date " ), 367 new MBeanParameterInfo ("toDate", "java.util.Date", 368 " The upper bound date " ), 369 new MBeanParameterInfo ("logLevel", "String", 370 " The minimum log level to display " ), 371 new MBeanParameterInfo ("onlyLevel", "Boolean", 372 " True to only display messsage for \"logLevel\""), 373 new MBeanParameterInfo ("listOfModules", "java.util.List", 374 " List Of Modules and Logger Names To Match" ), 375 new MBeanParameterInfo ("nameValueMap", "java.util.Properties", 376 " List Of Name Value Pairs to match " ) 377 }; 378 operationInfoArray[4] = new MBeanOperationInfo ( 379 GET_LOG_RECORD_USING_QUERY, 380 GET_LOG_RECORD_USING_QUERY_DESCRIPTION, 381 logviewerQueryParams, "javax.management.AttributeList", 382 MBeanOperationInfo.ACTION); 383 384 MBeanParameterInfo [] diagnosticsParameter = 385 {new MBeanParameterInfo ("messageId", "String", "Error Code") }; 386 operationInfoArray[5] = new MBeanOperationInfo ( 387 GET_DIAGNOSTIC_CAUSES_FOR_MESSAGEID, 388 GET_DIAGNOSTIC_CAUSES_FOR_MESSAGEID_DESCRIPTION, 389 diagnosticsParameter, "java.util.ArrayList", 390 MBeanOperationInfo.ACTION); 391 392 operationInfoArray[6] = new MBeanOperationInfo ( 393 GET_DIAGNOSTIC_CHECKS_FOR_MESSAGEID, 394 GET_DIAGNOSTIC_CHECKS_FOR_MESSAGEID_DESCRIPTION, 395 diagnosticsParameter, "java.util.ArrayList", 396 MBeanOperationInfo.ACTION); 397 398 operationInfoArray[7] = new MBeanOperationInfo ( 399 GET_DIAGNOSTIC_URI_FOR_MESSAGEID, 400 GET_DIAGNOSTIC_URI_FOR_MESSAGEID_DESCRIPTION, 401 diagnosticsParameter, "String", MBeanOperationInfo.ACTION); 402 403 operationInfoArray[8] = new MBeanOperationInfo ( 404 ROTATE_NOW, ROTATE_NOW_DESCRIPTION, 405 null, "void", MBeanOperationInfo.ACTION); 406 407 408 final MBeanParameterInfo [] getErrorDistributionParams = 409 { 410 new MBeanParameterInfo ("name", "long","time stamp"), 411 new MBeanParameterInfo ("name", Level .class.getName(), "log level") 412 }; 413 414 operationInfoArray[9] = new MBeanOperationInfo ( 415 GET_ERROR_DISTRIBUTION, GET_ERROR_DISTRIBUTION_DESCRIPTION, 416 getErrorDistributionParams, List .class.getName(), MBeanOperationInfo.INFO); 417 418 MBeanParameterInfo [] moduleNameParam = 419 {new MBeanParameterInfo ("ModuleName", "String", "Module Name")}; 420 operationInfoArray[10] = new MBeanOperationInfo ( 421 GETLOGNAMES4LOGMODULE, 422 GETLOGNAMES4LOGMODULE_DESCRIPTION, 423 moduleNameParam, "java.util.List", MBeanOperationInfo.ACTION); 424 425 String [] alarmTypes = {NOTIFICATION_SEVERE_ALARM, 426 NOTIFICATION_WARNING_ALARM}; 427 MBeanNotificationInfo [] notificationInfo = 428 {new MBeanNotificationInfo ( alarmTypes, "Alarms", 429 "Severe and Warning Log Messages will be notified ") }; 430 431 mBeanInfo = new MBeanInfo ("LogMBean", LOG_MBEAN_DESCRIPTION, 432 attributeInfoArray, null, operationInfoArray, 433 notificationInfo); 434 435 438 } catch( Exception e ) { 439 new ErrorManager ().error( 440 "Error in LogMBean Initialization", e, 441 ErrorManager.GENERIC_FAILURE ); 442 } 443 } 444 445 446 447 public Object invoke(String operationName, Object [] params, 448 String [] signature) throws MBeanException , ReflectionException 449 { 450 if( operationName == null || operationName.equals("")) { 451 throw new RuntimeOperationsException ( 452 new IllegalArgumentException ( "MBean.invoke operation name is "+ 453 " null " ) ); 454 } 455 AttributeList resultList = new AttributeList (); 456 if( operationName.equals( GET_LOGGER_NAMES ) ) { 457 return getLoggerNames( ); 458 } else if( operationName.equals( GET_LOGGER_NAMES_UNDER ) ) { 459 String loggerName = (String ) params[0]; 460 return getLoggerNamesUnder( loggerName ); 461 } else if( operationName.equals( GETLOGNAMES4LOGMODULE ) ) { 462 String module = (String ) params[0]; 463 return getLognames4LogModule(module); 464 } else if( operationName.equals( GET_LOG_LEVEL ) ) { 465 String loggerName = (String ) params[0]; 466 return getLogLevel( loggerName ); 467 } else if( operationName.equals( SET_LOG_LEVEL ) ) { 468 String loggerName = (String ) params[0]; 469 String loglevel = (String ) params[1]; 470 setLogLevel( loggerName, loglevel ); 471 } else if( operationName.equals( SET_LOG_LEVEL_FOR_MODULE ) ) { 472 String module = (String ) params[0]; 473 String loglevel = (String ) params[1]; 474 setLogLevel( module, loglevel ); 475 } else if( operationName.equals( GET_LOG_RECORD_USING_QUERY) ) { 476 String fileName = (String ) params[0]; 477 Long fromRecord = (Long ) params[1]; 478 Boolean next = (Boolean ) params[2]; 479 Boolean forward = (Boolean ) params[3]; 480 Integer requestedCount = (Integer ) params[4]; 481 Date fromDate = (Date ) params[5]; 482 Date toDate = (Date ) params[6]; 483 String logLevel = (String ) params[7]; 484 Boolean onlyLevel = (Boolean ) params[8]; 485 List listOfModules = (java.util.List ) params[9]; 486 java.util.Properties nvMap = (java.util.Properties ) params[10]; 487 return getLogRecordsUsingQuery( fileName, fromRecord, next, forward, 488 requestedCount, fromDate, toDate, logLevel, onlyLevel, 489 listOfModules, nvMap ); 490 } else if( operationName.equals( GET_ARCHIVED_LOG_FILES ) ) { 491 return getArchivedLogFiles( ); 492 } else if( operationName.equals( GET_DIAGNOSTIC_CAUSES_FOR_MESSAGEID )){ 493 String messageId = (String ) params[0]; 494 return 495 MessageIdCatalog.getInstance().getDiagnosticCausesForMessageId( 496 messageId ); 497 } else if( operationName.equals( GET_DIAGNOSTIC_CHECKS_FOR_MESSAGEID )){ 498 String messageId = (String ) params[0]; 499 return 500 MessageIdCatalog.getInstance().getDiagnosticChecksForMessageId( 501 messageId ); 502 } else if( operationName.equals( GET_DIAGNOSTIC_URI_FOR_MESSAGEID )){ 503 String messageId = (String ) params[0]; 504 return 505 MessageIdCatalog.getInstance().getDiagnosticURIForMessageId( 506 messageId ); 507 } else if( operationName.equals( ROTATE_NOW ) ) { 508 this.rotateNow( ); 509 } else if( operationName.equals( GET_LOGFILES_DIRECTORY ) ) { 510 return this.getLogFilesDirectory( ); 511 } else if( operationName.equals( GET_ERROR_DISTRIBUTION ) ) { 512 return this.getErrorDistribution( (Long )params[0], (Level )params[1] ); 513 } else { 514 throw new IllegalArgumentException ( 515 "Requested operation " + operationName + " does not exist..." ); 516 } 517 return resultList; 518 } 519 520 521 524 public boolean findLogger(String loggerName ) { 525 Enumeration allLoggers = LogManager.getLogManager().getLoggerNames( ); 526 while( allLoggers.hasMoreElements( ) ) { 527 String name = (String )allLoggers.nextElement(); 528 if (loggerName.equals(name)) 529 return true; 530 } 531 return false; 532 } 533 534 535 539 public List getLoggerNames( ) { 540 LinkedList loggerNamesList = new LinkedList ( ); 541 Enumeration allLoggers = LogManager.getLogManager().getLoggerNames( ); 542 while( allLoggers.hasMoreElements( ) ) { 543 loggerNamesList.add(allLoggers.nextElement( )); 544 } 545 return loggerNamesList; 546 } 547 548 552 public List getLoggerNamesUnder( String loggerName ) { 553 LinkedList filteredList = new LinkedList ( ); 554 Iterator allLoggersIterator = getLoggerNames( ).iterator( ); 555 while( allLoggersIterator.hasNext( ) ) { 556 String t = (String ) allLoggersIterator.next( ); 557 if( t.startsWith( loggerName ) ) { 558 filteredList.add( t ); 559 } 560 } 561 return filteredList; 562 } 563 564 565 570 public String getLogLevel( String loggerName ) { 571 String logLevelInString = null; 572 Logger logger = Logger.getLogger( loggerName ); 573 if( logger == null ) { 574 throw new RuntimeException ( " Logger " + loggerName + 575 " does not exist" ); 576 } 577 Level level = logger.getLevel( ); 578 boolean foundParentLevel = false; 579 if( level == null ) { 580 while( !foundParentLevel ) { 581 logger = logger.getParent(); 582 if ( logger == null ){ 583 break; 584 } 585 level = logger.getLevel( ); 586 if( level != null ) { 587 foundParentLevel = true; 588 } 589 } 590 } 591 if( level != null ) { 592 logLevelInString = level.toString(); 593 } 594 return logLevelInString; 595 } 596 597 610 public void setLogLevel( String loggerName, String level ) { 611 internalSetLogLevel(loggerName,Level.parse(level) ); 612 620 } 621 622 628 public void setLogLevelForModule( String module, String level ) { 629 String [] loggerNames = ModuleToLoggerNameMapper.getLoggerNames( module ); 630 for (int i=0;loggerNames!=null&&i<loggerNames.length;i++) { 631 setLogLevel(loggerNames[i], level ); 632 } 633 } 634 635 637 private void internalSetLogLevel( final String loggerName, 638 final Level level ) 639 { 640 AccessController.doPrivileged(new PrivilegedAction() { 641 public Object run() { 642 Logger.getLogger( loggerName ).setLevel(level); 643 return null; 644 }}); 645 } 646 647 672 public AttributeList getLogRecordsUsingQuery( 673 String logFilename, Long fromRecord, Boolean next, Boolean forward, 674 Integer requestedCount, Date fromDate, Date toDate, 675 String logLevel, Boolean onlyLevel, List listOfModules, 676 Properties nameValueMap) 677 { 678 return LogFilter.getLogRecordsUsingQuery(logFilename, fromRecord, next, 679 forward, requestedCount, fromDate, toDate, logLevel, onlyLevel, 680 listOfModules, nameValueMap); 681 } 682 683 688 public String [] getArchivedLogFiles( ) { 689 String [] archivedLogFiles = new String [0]; 690 try { 691 String instDir = System.getProperty( 692 SystemPropertyConstants.INSTANCE_ROOT_PROPERTY ); 693 String [] names = { instDir, LOGS_DIR }; 694 String logDir = StringUtils.makeFilePath( names, false ); 695 File file = new File ( logDir ); 696 archivedLogFiles = file.list( new FilenameFilterImpl( ) ); 697 String currentFileName = new File ( 703 ServerLogManager.getLogService( ).getFile( )).getName( ); 704 boolean foundCurrentFile = false; 705 int i = 0; 706 for( i = 0; i < archivedLogFiles.length; i++ ) { 707 if( currentFileName.equals( archivedLogFiles[i] ) ) { 708 foundCurrentFile = true; 709 break; 710 } 711 } 712 if( !foundCurrentFile ) { 713 String [] newArchivedLogFiles = new String [ archivedLogFiles.length + 1 ]; 717 newArchivedLogFiles[0] = currentFileName; 718 for( i = 1; i < (archivedLogFiles.length + 1); i++ ) { 719 newArchivedLogFiles[i] = archivedLogFiles[i - 1]; 720 } 721 return newArchivedLogFiles; 722 } 723 } catch( Exception e ) { 724 System.err.println( 727 "Exception in LogMBean.getArchivedLogFiles.." + e ); 728 throw new RuntimeException ( 729 "Exception in LogMBean.getArchivedLogFiles.." + e ); 730 } 731 return archivedLogFiles; 732 } 733 734 737 public void rotateNow( ) { 738 FileandSyslogHandler.getInstance( ).requestRotation( ); 739 this.rotateAccessLog( ); 741 } 742 743 746 public void rotateAccessLog( ) { 747 if( accessLogRotator != null ) { 748 accessLogRotator.rotate( ); 749 } 750 } 751 752 755 public void setAccessLogRotator( LogRotatorSPI logRotator ) { 756 accessLogRotator = logRotator; 757 } 758 759 762 public String getLogFilesDirectory( ) { 763 try { 764 String fileName = 765 FileandSyslogHandler.getInstance( ).getAbsoluteLogFileName( ); 766 return new File ( fileName ).getParent( ); 767 } catch( Exception e ) { 768 System.err.println( "Exception in LogMBean.getLogFilesDirectory()" 769 + e ); 770 } 771 return null; 772 } 773 774 775 778 public void changeLogFileName( String fileName ) { 779 FileandSyslogHandler.getInstance().changeFileName( fileName ); 780 } 781 782 783 789 public MBeanInfo getMBeanInfo() { 790 return mBeanInfo; 791 } 792 793 794 803 public Object getAttribute(String attribute) 804 throws AttributeNotFoundException 805 { 806 Object result = null; 807 808 if ( ATTR_LOGGER_NAMES.equals( attribute ) ) { 809 result = getLoggerNames(); 810 } 811 else if ( ATTR_LOGFILES_DIRECTORY.equals( attribute ) ) { 812 result = getLogFilesDirectory(); 813 } 814 else if ( ATTR_ARCHIVED_LOG_FILES.equals( attribute ) ) { 815 result = getArchivedLogFiles(); 816 } 817 else if ( ATTR_ERROR_INFORMATION.equals( attribute ) ) { 818 result = getErrorInformation(); 819 } 820 else if ( ATTR_KEEP_ERROR_STATISTICS_FOR_INTERVALS.equals( attribute ) ) { 821 result = getKeepErrorStatisticsForIntervals(); 822 } 823 else if ( ATTR_ERROR_STATISTICS_INTERVAL_DURATION.equals( attribute ) ) { 824 result = getErrorStatisticsIntervalMinutes(); 825 } 826 else if ( ATTR_KEEP_ERROR_STATISTICS_FOR_HOURS.equals( attribute ) ) { 827 result = getKeepErrorStatisticsForHours(); 828 } 829 else { 830 if (attribute != null) { 831 throw new AttributeNotFoundException ("Attribute " + attribute 832 + " not found in LogMBean. There are no attributes."); 833 } else { 834 throw new IllegalArgumentException ("Attribute Name is null"); 835 } 836 } 837 838 return result; 839 } 840 841 842 850 public AttributeList getAttributes( String [] attributeNames ) 851 { 852 final AttributeList attrs = new AttributeList (); 853 854 for( final String name : attributeNames ) 855 { 856 try 857 { 858 final Object value = getAttribute( name ); 859 attrs.add( new Attribute ( name, value ) ); 860 } 861 catch( Exception e ) 862 { 863 } 865 } 866 867 return attrs; 868 } 869 870 877 public AttributeList setAttributes( final AttributeList list ) { 878 final AttributeList result = new AttributeList (); 879 880 for( final Object o : list ) { 881 final Attribute attr = (Attribute )o; 882 883 try { 884 setAttribute( attr ); 885 result.add( attr ); 886 } 887 catch( Throwable t ) { 888 } 890 } 891 892 return result; 893 } 894 895 899 public void setAttribute( final Attribute attribute ) 900 throws AttributeNotFoundException { 901 final String name = attribute.getName(); 902 final Object value = attribute.getValue(); 903 904 if ( ATTR_KEEP_ERROR_STATISTICS_FOR_INTERVALS.equals( name ) ) { 905 setKeepErrorStatisticsForIntervals( (Integer )value ); 906 } 907 else if ( ATTR_ERROR_STATISTICS_INTERVAL_DURATION.equals( name ) ) { 908 setErrorStatisticsIntervalMinutes( (Long )value ); 909 } 910 else if ( ATTR_KEEP_ERROR_STATISTICS_FOR_HOURS.equals( name ) ) { 911 setKeepErrorStatisticsForHours( (Integer )value ); 912 } 913 else { 914 throw new AttributeNotFoundException ( name ); 915 } 916 } 917 918 private void raiseAlarm(String type, LogRecord record) { 919 LogAlarm logAlarm = new LogAlarm( type, this, record ); 920 sendNotification( logAlarm ); 921 } 922 923 926 void raiseWarningAlarm(LogRecord record) { 927 raiseAlarm( NOTIFICATION_WARNING_ALARM, record ); 928 } 929 930 933 void raiseSevereAlarm(LogRecord record) { 934 raiseAlarm( NOTIFICATION_SEVERE_ALARM, record ); 935 } 936 937 939 944 public void setKeepErrorStatisticsForIntervals( 945 final int numberOfIntervals) { 946 ErrorStatistics.singleton().setNumOfIntervals(numberOfIntervals); 947 } 948 949 952 public int getKeepErrorStatisticsForIntervals() { 953 return ErrorStatistics.singleton().getNumOfIntervals(); 954 } 955 956 961 public void setErrorStatisticsIntervalMinutes(final long minutes) { 962 ErrorStatistics.singleton().setIntervalDuration( 963 minutes*MINUTES_TO_MILLISECONDS); 964 } 965 966 969 public long getErrorStatisticsIntervalMinutes() { 970 return ErrorStatistics.singleton().getIntervalDuration() / 971 MINUTES_TO_MILLISECONDS; 972 } 973 974 979 public void setKeepErrorStatisticsForHours(final int hours) { 980 ErrorStatistics.singleton().setNumOfIntervals(hours); 981 } 982 983 986 public int getKeepErrorStatisticsForHours() { 987 return ErrorStatistics.singleton().getNumOfIntervals(); 988 } 989 990 994 public List <Map <String ,Object >> getErrorInformation() { 995 return ErrorStatistics.singleton().getErrorInformation(); 996 } 997 998 1002 public Map <String ,Integer > getErrorDistribution( 1003 long timeStamp, Level level) { 1004 return ErrorStatistics.singleton(). 1005 getErrorDistribution(timeStamp, level); 1006 } 1007 1008 1014 public List getLognames4LogModule(String logModuleName) { 1015 String [] names = ModuleToLoggerNameMapper.getLoggerNames(logModuleName); 1016 return Arrays.asList(names); 1017 } 1018} 1019 | Popular Tags |