0001: package com.sun.portal.fabric.mbeans;
0002:
0003: import com.sun.portal.admin.common.context.PSConfigContext;
0004: import com.sun.portal.admin.common.context.PortalDomainContext;
0005: import com.sun.portal.admin.server.mbeans.PSResource;
0006: import com.sun.portal.log.common.EnhancedProperties;
0007: import com.sun.portal.log.common.LoggerDetails;
0008: import com.sun.portal.log.common.LoggersList;
0009: import com.sun.portal.log.common.PortalLogFormatter;
0010: import com.sun.portal.log.common.PortalLogManager;
0011: import com.sun.portal.log.common.PortalLogger;
0012: import com.sun.portal.log.monitor.FileMonitor;
0013:
0014: import java.io.BufferedInputStream;
0015: import java.io.BufferedReader;
0016: import java.io.File;
0017: import java.io.FileInputStream;
0018: import java.io.FileOutputStream;
0019: import java.io.FilenameFilter;
0020: import java.io.IOException;
0021: import java.io.InputStream;
0022: import java.io.InputStreamReader;
0023: import java.text.SimpleDateFormat;
0024: import java.util.Collections;
0025: import java.util.Comparator;
0026: import java.util.Enumeration;
0027: import java.util.Date;
0028: import java.util.HashMap;
0029: import java.util.Hashtable;
0030: import java.util.Iterator;
0031: import java.util.LinkedList;
0032: import java.util.List;
0033: import java.util.Map;
0034: import java.util.Properties;
0035: import java.util.Set;
0036: import java.util.SortedSet;
0037: import java.util.StringTokenizer;
0038: import java.util.TreeMap;
0039: import java.util.TreeSet;
0040: import java.util.Vector;
0041: import java.util.logging.Level;
0042: import java.util.logging.Logger;
0043: import java.util.regex.Pattern;
0044:
0045: /**
0046: *
0047: */
0048: public class PortalLogConfigurator extends PSResource implements
0049: PortalLogConfiguratorMBean {
0050:
0051: private Properties defaultProperties = new Properties();
0052:
0053: public static final String PORTALS_DIR = "portals";
0054: public static final String CONFIG_DIR = "config";
0055: public static final String SEARCHSERVERS_DIR = "searchservers";
0056: public static final String DEFAULT_HANDLER = "java.util.logging.FileHandler";
0057:
0058: private static Logger logger = PortalLogger
0059: .getLogger(PortalLogConfigurator.class);
0060:
0061: // Constants used in UI should be same as that in LoggingUIConstants
0062: private static String LEVEL_UI = "level";
0063: private static String HANDLER_UI = "handler";
0064: private static String PATTERN_UI = "pattern";
0065: private static String LIMIT_UI = "limit";
0066: private static String COUNT_UI = "count";
0067: private static String APPEND_UI = "append";
0068: private static String FILTER_UI = "filter";
0069: private static String FORMATTER_UI = "formatter";
0070: private static String USE_SERVER_LOG_UI = "useServerLog";
0071: private static String PARENT_LEVEL = "ParentLevel";
0072:
0073: private static final String LOGGER_NAME_UI = "logger";
0074: private static final String SEPARATE_FILE_UI = "separateFile";
0075: private static final String USE_PARENT_UI = "useParent";
0076: private static final String STACKTRACE_UI = "stacktrace";
0077: private static final String LOGFILES_UI = "logfiles";
0078: public static final String LOGFILES_DIR_UI = "logfilesDir";
0079: public static final String LOGRECORDS_UI = "logrecords";
0080:
0081: private static final String INCLUDE_MORE_SEVERE_UI = "includeMoreSevere";
0082: private static final String SELECTED_MOST_RECENT_UI = "selectedMostRecent";
0083: //private static final String SELECTED_SPECIFIC_RANGE_UI = "selectedSpecificRange";
0084: private static final String SELECTED_SPECIFIC_RANGE_FROM_DATE_UI = "specificRangeFromDate";
0085: private static final String SELECTED_SPECIFIC_RANGE_TO_DATE_UI = "specificRangeToDate";
0086: private static final String SELECTED_SPECIFIC_RANGE_FROM_TIME_UI = "specificRangeFromTime";
0087: private static final String SELECTED_SPECIFIC_RANGE_TO_TIME_UI = "specificRangeToTime";
0088: private static final String SELECTED_LOG_FILE_NAME = "logFileName";
0089: private static final String TOTAL_LOG_RECORDS_FOR_MOST_RECENT = "totalLogRecords";
0090:
0091: // Formatters
0092: // The input format should be same the as the format keys defined in
0093: // ps\adminconsole\resources\logging.properties
0094: // The format keys are logviewer.date.format and logviewer.time.format
0095: private static final String INPUT_DATE_FORMAT = "MM/dd/yyyy";
0096: private static final String INPUT_TIME_FORMAT = "HH:mm:ss.SSS";
0097: private static final SimpleDateFormat logDateFormatter = new SimpleDateFormat(
0098: PortalLogFormatter.DATE_FORMAT);
0099: private static final SimpleDateFormat logDateTimeFormatter = new SimpleDateFormat(
0100: PortalLogFormatter.RFC_3339_DATE_FORMAT);
0101: private static final SimpleDateFormat inputDateFormatter = new SimpleDateFormat(
0102: INPUT_DATE_FORMAT);
0103: // "yyyy-MM-dd'T'HH:mm:ss.SSS"
0104: public static final String INPUT_DATE_TIME_FORMAT = INPUT_DATE_FORMAT
0105: + "'"
0106: + PortalLogFormatter.DATE_TIME_DELIMITER
0107: + "'"
0108: + INPUT_TIME_FORMAT;
0109: private static final SimpleDateFormat inputDateTimeFormatter = new SimpleDateFormat(
0110: INPUT_DATE_TIME_FORMAT);
0111:
0112: public void init(PSConfigContext cc, PortalDomainContext pdc,
0113: List path) {
0114: super .init(cc, pdc, path);
0115: //init default log configurations
0116: InputStream defaultConfigBundle = null;
0117: try {
0118: defaultConfigBundle = this .getClass().getClassLoader()
0119: .getResourceAsStream(
0120: PortalLogManager.DEFAULT_LOG_CONFIG_FILE);
0121: defaultProperties.load(defaultConfigBundle);
0122: } catch (Exception e) {
0123: logger.log(Level.SEVERE, "PSFB_CSPFM1104", e);
0124: } finally {
0125: if (defaultConfigBundle != null) {
0126: try {
0127: defaultConfigBundle.close();
0128: } catch (IOException e) {
0129: logger.log(Level.WARNING, "PSFB_CSPFM1104", e);
0130: }
0131: }
0132: }
0133: }
0134:
0135: public Vector listPSLoggers(String componentName,
0136: String componentID, String instance, Boolean detail)
0137: throws Exception {
0138: logger.log(Level.FINEST, "PSFB_CSPFM1009", new Object[] {
0139: componentName, componentID, instance });
0140: validateComponent(componentName);
0141: //get the log config file
0142: String logConfigFileName = getLogConfigFileName(componentName,
0143: componentID, instance);
0144: //get the logger list
0145: String loggerListFileName = getLoggerListFileName(
0146: componentName, logConfigFileName, instance);
0147: //derive the logger details
0148: Vector loggerDetails = getLoggersDetails(componentName,
0149: logConfigFileName, loggerListFileName, detail);
0150: return loggerDetails;
0151: }
0152:
0153: private String getLoggerListFileName(String componentName,
0154: String logConfigFileName, String instance) {
0155: String loggerListFileName = LoggersList.getListLoggerFile(
0156: componentName, logConfigFileName, instance);
0157: logger.log(Level.FINE, "PSFB_CSPFM1006", loggerListFileName);
0158: return loggerListFileName;
0159: }
0160:
0161: private Vector getLoggersDetails(String componentName,
0162: String logConfigFileName, String loggerListFileName,
0163: Boolean detail) throws Exception {
0164: Vector loggerDetails = new Vector();
0165: if (detail.booleanValue()) {
0166: //send with details
0167: Vector loggerList = getLoggerList(loggerListFileName);
0168: Map loggerDetailsMap = getLoggerDetails(componentName,
0169: logConfigFileName, loggerList);
0170: loggerDetails = getFormattedLoggerDetails(loggerList,
0171: loggerDetailsMap);
0172: } else {
0173: // Sort the logger names
0174: Vector loggerList = getLoggerList(loggerListFileName);
0175: Set sortedLoggerList = Collections
0176: .synchronizedSet(new TreeSet());
0177: sortedLoggerList.addAll(loggerList);
0178: loggerDetails.addAll(sortedLoggerList);
0179: }
0180: return loggerDetails;
0181: }
0182:
0183: private Vector getLoggerList(String loggersListFileName)
0184: throws Exception {
0185: Vector loggerList = new Vector();
0186: InputStream is = null;
0187: try {
0188: Properties props = new Properties();
0189: is = new FileInputStream(new File(loggersListFileName));
0190: props.load(is);
0191: props.keys();
0192: loggerList = new Vector(props.keySet());
0193: } catch (Exception e) {
0194: logger.log(Level.WARNING, "PSFB_CSPFM1008", e);
0195: throw new Exception("Invalid componentId or instance");
0196: //log
0197: } finally {
0198: if (is != null) {
0199: try {
0200: is.close();
0201: } catch (IOException e) {
0202: logger.log(Level.WARNING, "PSFB_CSPFM1008", e);
0203: }
0204: }
0205: }
0206: return loggerList;
0207: }
0208:
0209: private LoggerDetails getLoggerDetails(String componentName,
0210: String loggerName, EnhancedProperties props) {
0211: LoggerDetails details = new LoggerDetails();
0212: details.setLoggerName(loggerName);
0213: details.setLevel(getLevel(loggerName, props));
0214: details.setLogToParent(getLogToParent(loggerName, props));
0215: details
0216: .setStackTraceValue(getStackTraceValue(loggerName,
0217: props));
0218: details.setHandlers(getHandlers(componentName, loggerName,
0219: props));
0220: details
0221: .setPattern(getPattern(componentName, loggerName, props));
0222: return details;
0223: }
0224:
0225: /**
0226: * Returns a list of child loggers from the list of given loggerNames
0227: * for the given logger.
0228: * The list includes the logger.
0229: *
0230: * @param loggerName the name of the logger
0231: * @return list of child loggers.
0232: */
0233: private Vector getChildLoggers(String loggerName, Vector loggerNames) {
0234: String loggerNamespace = loggerName + ".";
0235: int numberOfLoggers = loggerNames.size();
0236: String childLoggerName;
0237: Vector childLoggers = new Vector();
0238: for (int i = 0; i < numberOfLoggers; i++) {
0239: childLoggerName = (String) loggerNames.get(i);
0240: if (childLoggerName.equals(loggerName)
0241: || childLoggerName.startsWith(loggerNamespace)) {
0242: childLoggers.add(childLoggerName);
0243: }
0244: }
0245: return childLoggers;
0246: }
0247:
0248: /**
0249: * Returns the childLoggers in ascending order
0250: *
0251: * @param childLoggers vector of childLogger names.
0252: * @return
0253: */
0254: private Set getSortedChildLoggers(Vector childLoggers) {
0255: Set sortedChildLoggers = Collections
0256: .synchronizedSet(new TreeSet());
0257: sortedChildLoggers.addAll(childLoggers);
0258: return sortedChildLoggers;
0259: }
0260:
0261: /**
0262: * Formats the logger detail information.
0263: *
0264: * @param loggerDetails
0265: * @param fileInfo
0266: * @return
0267: */
0268: private String format(LoggerDetails loggerDetails, boolean fileInfo) {
0269: // Format
0270: return loggerDetails.format(fileInfo, false);
0271: }
0272:
0273: /**
0274: * Returns the details about all the loggers.
0275: * Formatting of the logger is handled by PortalLoggerDetail.
0276: *
0277: * @return
0278: */
0279: private Vector getFormattedLoggerDetails(Vector loggerNames,
0280: Map loggerDetailsMap) {
0281:
0282: Vector loggerDetails = new Vector();
0283: SortedSet loggersWithSeparateFile = new TreeSet(
0284: new LoggerComparator());
0285: int numberOfLoggers = loggerNames.size();
0286: String loggerName;
0287: // Get a list of loggers which have separate files and sort it in
0288: // the descending order.
0289: // This list should not contain "debug.com.sun.portal" as its handled
0290: // separately.
0291: for (int i = 0; i < numberOfLoggers; i++) {
0292: loggerName = (String) loggerNames.get(i);
0293: if (!loggerName.equals(PortalLogManager.DEBUG_ROOT_LOGGER)
0294: && ((LoggerDetails) loggerDetailsMap
0295: .get(loggerName)).getPattern() != null) {
0296:
0297: loggersWithSeparateFile.add(loggerName);
0298: }
0299: }
0300:
0301: // For all the loggers that have separate file , find the list
0302: // of child loggers and save it in a HashMap.
0303: // Remove this child loggers from the logger list, as the same list
0304: // is used to get the child loggers.
0305: Vector childLoggers;
0306: Map childLoggersMap = Collections
0307: .synchronizedMap(new TreeMap());
0308: Iterator itr = loggersWithSeparateFile.iterator();
0309: while (itr.hasNext()) {
0310: loggerName = (String) itr.next();
0311: childLoggers = getChildLoggers(loggerName, loggerNames);
0312: childLoggersMap.put(loggerName,
0313: getSortedChildLoggers(childLoggers));
0314: loggerNames.removeAll(childLoggers);
0315: }
0316:
0317: // Now get the child loggers for "debug.com.sun.portal"
0318: childLoggers = getChildLoggers(
0319: PortalLogManager.DEBUG_ROOT_LOGGER, loggerNames);
0320: childLoggersMap.put(PortalLogManager.DEBUG_ROOT_LOGGER,
0321: getSortedChildLoggers(childLoggers));
0322:
0323: // Format the loggers
0324: Set mappings = childLoggersMap.entrySet();
0325: itr = mappings.iterator();
0326: Map.Entry mapEntry;
0327: String childLoggerName;
0328: Set sortedChildLoggers;
0329: Iterator childItr;
0330: while (itr.hasNext()) {
0331: mapEntry = (Map.Entry) itr.next();
0332: sortedChildLoggers = (Set) mapEntry.getValue();
0333: childItr = sortedChildLoggers.iterator();
0334: while (childItr.hasNext()) {
0335: childLoggerName = (String) childItr.next();
0336: loggerDetails.add(format(
0337: (LoggerDetails) loggerDetailsMap
0338: .get(childLoggerName), true));
0339: }
0340: }
0341: return loggerDetails;
0342: }
0343:
0344: private String getPattern(String componentName, String loggerName,
0345: EnhancedProperties props) {
0346: // Check whether the handler for the loggerName has .pattern attribute
0347: // If yes, return its pattern
0348: StringBuffer loggerPatternBuff = new StringBuffer();
0349: loggerPatternBuff.append(loggerName).append(
0350: PortalLogManager.LOG_HANDLER_ATTRIBUTE).append(".");
0351: String handlerName;
0352: if (LoggersList.COMPONENT_SEARCH_INSTANCE.equals(componentName)) {
0353: handlerName = (String) props
0354: .get(PortalLogManager.DEBUG_ROOT_LOGGER_SEARCH
0355: + PortalLogManager.LOG_HANDLER_ATTRIBUTE);
0356: } else {
0357: handlerName = (String) props
0358: .get(PortalLogManager.DEBUG_ROOT_LOGGER
0359: + PortalLogManager.LOG_HANDLER_ATTRIBUTE);
0360: }
0361: loggerPatternBuff.append(handlerName).append(
0362: PortalLogManager.LOG_HANDLER_PATTERN_ATTRIBUTE);
0363: if (props.containsKey(loggerPatternBuff.toString())) {
0364: return (String) props.get(loggerPatternBuff.toString());
0365: }
0366: // Check whether the loggerName has .separatefile attribute
0367: // If yes, return the pattern of its parent
0368: if (props.containsKey(loggerName
0369: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE)) {
0370: return getLoggerProperty(
0371: props,
0372: loggerName,
0373: PortalLogManager.LOG_HANDLER_ATTRIBUTE
0374: + "."
0375: + DEFAULT_HANDLER
0376: + PortalLogManager.LOG_HANDLER_PATTERN_ATTRIBUTE);
0377: }
0378: return null;
0379: }
0380:
0381: private String[] getHandlers(String componentName,
0382: String loggerName, EnhancedProperties props) {
0383: Vector handlers = new Vector();
0384: handlers.add(getLoggerProperty(props, loggerName,
0385: PortalLogManager.LOG_HANDLER_ATTRIBUTE));
0386:
0387: // Check whether the loggerName has .separatefile attribute
0388: // If yes, return the pattern of its parent
0389: if (props.containsKey(loggerName
0390: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE)
0391: && handlers.size() == 0) {
0392: handlers.add(getLoggerProperty(props, loggerName,
0393: PortalLogManager.LOG_HANDLER_ATTRIBUTE));
0394: }
0395:
0396: String[] handlersA = new String[handlers.size()];
0397: convert(handlers, handlersA);
0398: return handlersA;
0399: }
0400:
0401: private void convert(Vector v, String[] sa) {
0402: for (int i = 0; i < v.size(); i++) {
0403: sa[i] = (String) v.get(i);
0404: }
0405: }
0406:
0407: private String getStackTraceValue(String loggerName,
0408: EnhancedProperties props) {
0409: if (props.containsKey(loggerName
0410: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE)) {
0411: return (String) props.get(loggerName
0412: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE);
0413: }
0414: return "false";
0415: }
0416:
0417: private String getLogToParent(String loggerName,
0418: EnhancedProperties props) {
0419: if (props.containsKey(loggerName
0420: + PortalLogManager.LOG_USE_PARENT_HANDLER)) {
0421: return (String) props.get(loggerName
0422: + PortalLogManager.LOG_USE_PARENT_HANDLER);
0423: } else if (PortalLogManager.DEBUG_ROOT_LOGGER
0424: .equals(loggerName)) {
0425: return "false";
0426: }
0427: return "true";
0428: }
0429:
0430: private String getLevel(String loggerName, EnhancedProperties props) {
0431: return getLoggerProperty(props, loggerName,
0432: PortalLogManager.LOG_LEVEL_ATTRIBUTE);
0433: }
0434:
0435: private Map getLoggerDetails(String componentName,
0436: String logConfigFileName, Vector loggerList)
0437: throws IOException {
0438: Map loggerDetailsMap = Collections
0439: .synchronizedMap(new HashMap());
0440: int numberOfLoggers = loggerList.size();
0441: String loggerName;
0442: EnhancedProperties props = getProps(logConfigFileName);
0443: for (int i = 0; i < numberOfLoggers; i++) {
0444: loggerName = (String) loggerList.get(i);
0445: loggerDetailsMap.put(loggerName, getLoggerDetails(
0446: componentName, loggerName, props));
0447: }
0448: return loggerDetailsMap;
0449:
0450: }
0451:
0452: private String getLogConfigFileName(String componentName,
0453: String componentID, String instance) {
0454: StringBuffer logConfigFileName = new StringBuffer();
0455: if (LoggersList.COMPONENT_PORTAL_INSTANCE.equals(componentName)) {
0456: //portal => psdatadir/portals/componentID/config/PSLogConfig.properties
0457: // componentID is the portalId
0458: logConfigFileName.append(cc.getPSDataDir());
0459: logConfigFileName.append(fs);
0460: logConfigFileName.append(PORTALS_DIR);
0461: logConfigFileName.append(fs);
0462: logConfigFileName.append(componentID);
0463: logConfigFileName.append(fs);
0464: logConfigFileName.append(CONFIG_DIR);
0465: logConfigFileName.append(fs);
0466: logConfigFileName
0467: .append(PortalLogManager.LOG_CONFIG_FILENAME);
0468: } else if (LoggersList.COMPONENT_GW_INSTANCE
0469: .equals(componentName)
0470: || LoggersList.COMPONENT_NLP_INSTANCE
0471: .equals(componentName)
0472: || LoggersList.COMPONENT_RWP_INSTANCE
0473: .equals(componentName)) {
0474: //SRA => psconfigdir/platform.conf.instance
0475: // instance is the instance-name
0476: logConfigFileName.append(cc.getPSConfigDir());
0477: logConfigFileName.append(fs);
0478: logConfigFileName
0479: .append(PortalLogManager.SRA_LOG_CONFIG_FILENAME_PREFIX);
0480: logConfigFileName.append(instance);
0481: } else if (LoggersList.COMPONENT_SEARCH_INSTANCE
0482: .equals(componentName)) {
0483: //search => psdatadir/searchservers/componentID/config/SearchLogConfig.properties
0484: // componentID is the searchserverId
0485: logConfigFileName.append(cc.getPSDataDir());
0486: logConfigFileName.append(fs);
0487: logConfigFileName.append(SEARCHSERVERS_DIR);
0488: logConfigFileName.append(fs);
0489: logConfigFileName.append(componentID);
0490: logConfigFileName.append(fs);
0491: logConfigFileName.append(CONFIG_DIR);
0492: logConfigFileName.append(fs);
0493: logConfigFileName
0494: .append(PortalLogManager.SEARCH_LOG_CONFIG_FILENAME);
0495: } else if (LoggersList.COMPONENT_PAS_INSTANCE
0496: .equals(componentName)
0497: || LoggersList.COMPONENT_PSCONSOLE_INSTANCE
0498: .equals(componentName)) {
0499: //Admin(PAS or Console) => psconfigdir/AdminLogConfig.properties
0500: logConfigFileName.append(cc.getPSConfigDir());
0501: logConfigFileName.append(fs);
0502: logConfigFileName
0503: .append(PortalLogManager.ADMIN_LOG_CONFIG_FILENAME);
0504: } else {
0505: //rest of them!
0506: logConfigFileName.append(cc.getPSConfigDir());
0507: logConfigFileName.append(fs);
0508: logConfigFileName
0509: .append(PortalLogManager.LOG_CONFIG_FILENAME);
0510: }
0511: logger.log(Level.FINE, "PSFB_CSPFM1007", logConfigFileName);
0512: return logConfigFileName.toString();
0513: }
0514:
0515: public void setLevel(String componentName, String componentID,
0516: String instance, String loggerName, String level)
0517: throws Exception {
0518: logger.log(Level.INFO, "PSFB_CSPFM1010",
0519: new Object[] { componentName, componentID, instance,
0520: loggerName, level });
0521: validateInput(componentName, componentID, instance, loggerName,
0522: level);
0523: EnhancedProperties props = getProps(componentName, componentID,
0524: instance);
0525: checkConfigurationAllowed(props);
0526: props.put(loggerName + PortalLogManager.LOG_LEVEL_ATTRIBUTE,
0527: level);
0528: String logConfigFileName = getLogConfigFileName(componentName,
0529: componentID, instance);
0530: store(props, componentName, logConfigFileName);
0531: }
0532:
0533: private void validateLoggerName(String loggerListFilename,
0534: String loggerName) throws Exception {
0535: if (!loggerName.startsWith(PortalLogManager.DEBUG_ROOT_LOGGER))
0536: throw new Exception("invalid logger");
0537: Vector loggerList = getLoggerList(loggerListFilename);
0538: if (!loggerList.contains(loggerName))
0539: throw new Exception("Invalid logger specified: "
0540: + loggerName);
0541: }
0542:
0543: private void validateLevel(String level) throws Exception {
0544: try {
0545: Level.parse(level);
0546: } catch (Exception e) {
0547: throw new Exception("Invalid level specified: " + level);
0548: }
0549: }
0550:
0551: public static void validateComponent(String componentName)
0552: throws Exception {
0553: if (!(LoggersList.COMPONENT_PORTAL_INSTANCE
0554: .equals(componentName)
0555: || LoggersList.COMPONENT_GW_INSTANCE
0556: .equals(componentName)
0557: || LoggersList.COMPONENT_NLP_INSTANCE
0558: .equals(componentName)
0559: || LoggersList.COMPONENT_RWP_INSTANCE
0560: .equals(componentName)
0561: || LoggersList.COMPONENT_SEARCH_INSTANCE
0562: .equals(componentName)
0563: || LoggersList.COMPONENT_PAS_INSTANCE
0564: .equals(componentName) || LoggersList.COMPONENT_PSCONSOLE_INSTANCE
0565: .equals(componentName))) {
0566:
0567: StringBuffer validComponentList = new StringBuffer(
0568: " Valid component names are ");
0569: validComponentList
0570: .append(LoggersList.COMPONENT_PORTAL_INSTANCE);
0571: validComponentList.append(" ");
0572: validComponentList
0573: .append(LoggersList.COMPONENT_SEARCH_INSTANCE);
0574: validComponentList.append(" ");
0575: validComponentList
0576: .append(LoggersList.COMPONENT_PAS_INSTANCE);
0577: validComponentList.append(" ");
0578: validComponentList
0579: .append(LoggersList.COMPONENT_PSCONSOLE_INSTANCE);
0580: validComponentList.append(" ");
0581: validComponentList
0582: .append(LoggersList.COMPONENT_GW_INSTANCE);
0583: validComponentList.append(" ");
0584: validComponentList
0585: .append(LoggersList.COMPONENT_NLP_INSTANCE);
0586: validComponentList.append(" ");
0587: validComponentList
0588: .append(LoggersList.COMPONENT_RWP_INSTANCE);
0589: throw new Exception("Invalid component specified: "
0590: + componentName + validComponentList);
0591: }
0592: }
0593:
0594: private void validateInput(String componentName,
0595: String componentID, String instance, String loggerName,
0596: String level) throws Exception {
0597:
0598: validateInput(componentName, componentID, instance, loggerName);
0599: // validate level
0600: validateLevel(level);
0601: }
0602:
0603: private void validateInput(String componentName,
0604: String componentID, String instance, String loggerName)
0605: throws Exception {
0606: String logConfigFileName = getLogConfigFileName(componentName,
0607: componentID, instance);
0608: String loggerListFilename = getLoggerListFileName(
0609: componentName, logConfigFileName, instance);
0610:
0611: // validate componentName
0612: validateComponent(componentName);
0613: // validate the loggerName
0614: validateLoggerName(loggerListFilename, loggerName);
0615:
0616: }
0617:
0618: private void store(EnhancedProperties props, String componentName,
0619: String logConfigFileName) throws IOException {
0620: FileOutputStream oStream = null;
0621: FileOutputStream monitoredFileStream = null;
0622: try {
0623: oStream = new FileOutputStream(new File(logConfigFileName));
0624: props.store(oStream, null);
0625: String monitoredConfigFileName = FileMonitor
0626: .getMonitoredConfigFile(logConfigFileName);
0627: // For sra components append component name to the monitored file name
0628: if (LoggersList.COMPONENT_GW_INSTANCE.equals(componentName)
0629: || LoggersList.COMPONENT_NLP_INSTANCE
0630: .equals(componentName)
0631: || LoggersList.COMPONENT_RWP_INSTANCE
0632: .equals(componentName)) {
0633: monitoredConfigFileName = monitoredConfigFileName + "."
0634: + componentName;
0635: }
0636: logger.log(Level.FINEST, "PSFB_CSPFM1127",
0637: monitoredConfigFileName);
0638: monitoredFileStream = new FileOutputStream(
0639: monitoredConfigFileName);
0640: } finally {
0641: try {
0642: if (oStream != null)
0643: oStream.close();
0644: } catch (Exception e) {
0645: //drop-through
0646: }
0647: try {
0648: if (monitoredFileStream != null)
0649: monitoredFileStream.close();
0650: } catch (Exception e) {
0651: //drop-through
0652: }
0653: }
0654: }
0655:
0656: private boolean userServerLogs(EnhancedProperties props) {
0657: return (props.containsKey(PortalLogManager.DEBUG_ROOT_LOGGER
0658: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE) && "true"
0659: .equals(props.get(PortalLogManager.DEBUG_ROOT_LOGGER
0660: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE)));
0661:
0662: }
0663:
0664: /**
0665: * Returns the logger parent till root logger.
0666: *
0667: * @param loggerName the name of the logger
0668: * @return the logger name space.
0669: */
0670:
0671: private String getParent(String loggerName) {
0672: int lastIndex = loggerName.lastIndexOf(".");
0673: if (lastIndex == -1)
0674: return PortalLogManager.DEBUG_ROOT_LOGGER;
0675: return (loggerName.substring(0, lastIndex));
0676: }
0677:
0678: /**
0679: * Searches for the property with the specified logger name and attribute
0680: * in the config property list and returns the value.
0681: *
0682: * @param loggerName the name of the logger
0683: * @param attribute the name of the attribute
0684: * @return the value in the config property list with the specified logger name and
0685: * attribute.
0686: */
0687: private String getLoggerProperty(Properties props,
0688: String loggerName, String attribute) {
0689: String value = props.getProperty(loggerName + attribute);
0690: while (value == null
0691: && !loggerName
0692: .equals(PortalLogManager.DEBUG_ROOT_LOGGER)) {
0693: loggerName = getParent(loggerName);
0694: value = props.getProperty(loggerName + attribute);
0695: }
0696: return value;
0697: }
0698:
0699: public String getLevel(String loggerName, String componentName,
0700: String componentID, String instance) throws Exception {
0701: validateInput(componentName, componentID, instance, loggerName);
0702: return getLoggerProperty(getProps(componentName, componentID,
0703: instance), loggerName,
0704: PortalLogManager.LOG_LEVEL_ATTRIBUTE);
0705: }
0706:
0707: public void setSeparateLogFile(String componentName,
0708: String componentID, String instance, String loggerName,
0709: String level, Boolean printStackTrace, Boolean logInParent)
0710: throws Exception {
0711: logger.log(Level.INFO, "PSFB_CSPFM1011", new Object[] {
0712: componentName, componentID, instance, loggerName,
0713: level, printStackTrace, logInParent });
0714: //if loggerName is root logger, don't do anything
0715: if (PortalLogManager.DEBUG_ROOT_LOGGER.equals(loggerName))
0716: return;
0717: validateInput(componentName, componentID, instance, loggerName,
0718: level);
0719: // Both printStackTrace and logInParent cannot be true
0720: if (printStackTrace.booleanValue()
0721: && logInParent.booleanValue()) {
0722: logger.severe("PSALI_CSPACCL0002");
0723: throw new Exception(
0724: "Both printStackTrace and logInParent cannot be true");
0725: }
0726: EnhancedProperties props = getProps(componentName, componentID,
0727: instance);
0728: checkConfigurationAllowed(props);
0729: props.put(loggerName + PortalLogManager.LOG_LEVEL_ATTRIBUTE,
0730: level);
0731: props.put(loggerName
0732: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE, "true");
0733: props.put(loggerName + PortalLogManager.LOG_USE_PARENT_HANDLER,
0734: logInParent.toString());
0735: props.put(loggerName
0736: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE,
0737: printStackTrace.toString());
0738: //get the log config file
0739: String logConfigFileName = getLogConfigFileName(componentName,
0740: componentID, instance);
0741: store(props, componentName, logConfigFileName);
0742: }
0743:
0744: public void reset(String componentName, String componentID,
0745: String instance, String loggerName) throws Exception {
0746: logger.log(Level.INFO, "PSFB_CSPFM1012", new Object[] {
0747: componentName, componentID, instance, loggerName });
0748: //if loggerName is root logger, don't do anything
0749: if (PortalLogManager.DEBUG_ROOT_LOGGER.equals(loggerName))
0750: return;
0751: validateInput(componentName, componentID, instance, loggerName);
0752: EnhancedProperties props = getProps(componentName, componentID,
0753: instance);
0754: checkConfigurationAllowed(props);
0755: if (!props.containsKey(loggerName
0756: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE)) {
0757: throw new Exception("The specified logger " + loggerName
0758: + " does not have a Handler attached to it.");
0759: }
0760: props.remove(loggerName + PortalLogManager.LOG_LEVEL_ATTRIBUTE);
0761: props.remove(loggerName
0762: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE);
0763: props.remove(loggerName
0764: + PortalLogManager.LOG_USE_PARENT_HANDLER);
0765: props.remove(loggerName
0766: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE);
0767: String logConfigFileName = getLogConfigFileName(componentName,
0768: componentID, instance);
0769: store(props, componentName, logConfigFileName);
0770: }
0771:
0772: private EnhancedProperties getProps(String componentName,
0773: String componentID, String instance) throws IOException {
0774: //get the log config file
0775: String logConfigFileName = getLogConfigFileName(componentName,
0776: componentID, instance);
0777: return getProps(logConfigFileName);
0778: }
0779:
0780: private EnhancedProperties getProps(String logConfigFileName)
0781: throws IOException {
0782: EnhancedProperties props = new EnhancedProperties(
0783: defaultProperties);
0784: load(props, logConfigFileName);
0785: return props;
0786: }
0787:
0788: private void load(EnhancedProperties props, String logConfigFileName)
0789: throws IOException {
0790: BufferedInputStream iStream = new BufferedInputStream(
0791: new FileInputStream(new File(logConfigFileName)));
0792: props.load(iStream);
0793: iStream.close();
0794: }
0795:
0796: private void checkConfigurationAllowed(EnhancedProperties props)
0797: throws Exception {
0798: //if use server logs, throw exception saying so
0799: if (userServerLogs(props))
0800: throw new Exception(
0801: "Portal logs are routed to server log file. So no log configuration is applied.");
0802: }
0803:
0804: /**
0805: *
0806: * @param componentName
0807: * @param componentID
0808: * @param instance
0809: * @return
0810: * @throws Exception
0811: */
0812: /**
0813: * Hashtable=>
0814: * "level"->string val
0815: * "handler"->string val
0816: * "pattern"->string val
0817: * "limit"->string val
0818: * "count"->string val
0819: * "append"->string val
0820: * "filter"->string val
0821: * "formatter"->string val
0822: * "customHandler"->string val
0823: * "useServerLog"->string val
0824: */
0825:
0826: public Hashtable getCommonLogDetails(String componentName,
0827: String componentID, String instance) throws Exception {
0828: logger.log(Level.INFO, "PSFB_CSPFM1013", new Object[] {
0829: componentName, componentID, instance });
0830: String loggerName = getLoggerName(componentName);
0831: validateInput(componentName, componentID, instance, loggerName);
0832: Hashtable values = new Hashtable();
0833: EnhancedProperties props = getProps(componentName, componentID,
0834: instance);
0835: values.put(LEVEL_UI, getLoggerProperty(props, loggerName,
0836: PortalLogManager.LOG_LEVEL_ATTRIBUTE));
0837: values.put(HANDLER_UI, getLoggerProperty(props, loggerName,
0838: PortalLogManager.LOG_HANDLER_ATTRIBUTE));
0839: values
0840: .put(
0841: PATTERN_UI,
0842: getLoggerProperty(
0843: props,
0844: loggerName,
0845: PortalLogManager.LOG_HANDLER_ATTRIBUTE
0846: + "."
0847: + DEFAULT_HANDLER
0848: + PortalLogManager.LOG_HANDLER_PATTERN_ATTRIBUTE));
0849: values
0850: .put(
0851: LIMIT_UI,
0852: getLoggerProperty(
0853: props,
0854: loggerName,
0855: PortalLogManager.LOG_HANDLER_ATTRIBUTE
0856: + "."
0857: + DEFAULT_HANDLER
0858: + PortalLogManager.LOG_HANDLER_LIMIT_ATTRIBUTE));
0859: values
0860: .put(
0861: COUNT_UI,
0862: getLoggerProperty(
0863: props,
0864: loggerName,
0865: PortalLogManager.LOG_HANDLER_ATTRIBUTE
0866: + "."
0867: + DEFAULT_HANDLER
0868: + PortalLogManager.LOG_HANDLER_COUNT_ATTRIBUTE));
0869: values
0870: .put(
0871: APPEND_UI,
0872: getLoggerProperty(
0873: props,
0874: loggerName,
0875: PortalLogManager.LOG_HANDLER_ATTRIBUTE
0876: + "."
0877: + DEFAULT_HANDLER
0878: + PortalLogManager.LOG_HANDLER_APPEND_ATTRIBUTE));
0879: values
0880: .put(
0881: FILTER_UI,
0882: getLoggerProperty(
0883: props,
0884: loggerName,
0885: PortalLogManager.LOG_HANDLER_ATTRIBUTE
0886: + "."
0887: + DEFAULT_HANDLER
0888: + PortalLogManager.LOG_HANDLER_FILTER_ATTRIBUTE));
0889: values
0890: .put(
0891: FORMATTER_UI,
0892: getLoggerProperty(
0893: props,
0894: loggerName,
0895: PortalLogManager.LOG_HANDLER_ATTRIBUTE
0896: + "."
0897: + DEFAULT_HANDLER
0898: + PortalLogManager.LOG_HANDLER_FORMATTER_ATTRIBUTE));
0899: values
0900: .put(
0901: USE_SERVER_LOG_UI,
0902: ""
0903: + (props
0904: .containsKey(PortalLogManager.DEBUG_ROOT_LOGGER
0905: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE) && "true"
0906: .equals(props
0907: .get(PortalLogManager.DEBUG_ROOT_LOGGER
0908: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE))));
0909: return values;
0910: }
0911:
0912: private String getLoggerName(String componentName) {
0913: if (LoggersList.COMPONENT_SEARCH_INSTANCE.equals(componentName)) {
0914: return PortalLogManager.DEBUG_ROOT_LOGGER_SEARCH;
0915: }
0916: return PortalLogManager.DEBUG_ROOT_LOGGER;
0917: }
0918:
0919: public void setCommonLogDetails(String componentName,
0920: String componentID, String instance, Hashtable values)
0921: throws Exception {
0922: logger.log(Level.INFO, "PSFB_CSPFM1001", new Object[] {
0923: componentName, componentID, instance, values });
0924:
0925: String loggerName = getLoggerName(componentName);
0926: validateInput(componentName, componentID, instance, loggerName);
0927: EnhancedProperties props = getProps(componentName, componentID,
0928: instance);
0929: Object val = values.get(LEVEL_UI);
0930: if (val != null)
0931: props.setProperty(loggerName
0932: + PortalLogManager.LOG_LEVEL_ATTRIBUTE,
0933: (String) val);
0934: val = values.get(HANDLER_UI);
0935: if (val != null)
0936: props.setProperty(loggerName
0937: + PortalLogManager.LOG_HANDLER_ATTRIBUTE,
0938: (String) val);
0939: val = values.get(LIMIT_UI);
0940: if (val != null)
0941: props.setProperty(loggerName
0942: + PortalLogManager.LOG_HANDLER_ATTRIBUTE + "."
0943: + DEFAULT_HANDLER
0944: + PortalLogManager.LOG_HANDLER_LIMIT_ATTRIBUTE,
0945: (String) val);
0946: val = values.get(COUNT_UI);
0947: if (val != null)
0948: props.setProperty(loggerName
0949: + PortalLogManager.LOG_HANDLER_ATTRIBUTE + "."
0950: + DEFAULT_HANDLER
0951: + PortalLogManager.LOG_HANDLER_COUNT_ATTRIBUTE,
0952: (String) val);
0953: val = values.get(APPEND_UI);
0954: if (val != null)
0955: props.setProperty(loggerName
0956: + PortalLogManager.LOG_HANDLER_ATTRIBUTE + "."
0957: + DEFAULT_HANDLER
0958: + PortalLogManager.LOG_HANDLER_APPEND_ATTRIBUTE,
0959: (String) val);
0960: val = values.get(FILTER_UI);
0961: if (val != null)
0962: props.setProperty(loggerName
0963: + PortalLogManager.LOG_HANDLER_ATTRIBUTE + "."
0964: + DEFAULT_HANDLER
0965: + PortalLogManager.LOG_HANDLER_FILTER_ATTRIBUTE,
0966: (String) val);
0967: val = values.get(USE_SERVER_LOG_UI);
0968: if (val != null)
0969: props.setProperty(loggerName
0970: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE,
0971: (String) val);
0972: String logConfigFileName = getLogConfigFileName(componentName,
0973: componentID, instance);
0974: store(props, componentName, logConfigFileName);
0975: }
0976:
0977: private Properties getLoggersListProps(String componentName,
0978: String componentID, String instance) throws IOException {
0979: Properties loggersListProps = new Properties();
0980: FileInputStream is = null;
0981: try {
0982: is = new FileInputStream(getLoggerListFileName(
0983: componentName, getLogConfigFileName(componentName,
0984: componentID, instance), instance));
0985: loggersListProps.load(is);
0986: } finally {
0987: if (is != null)
0988: is.close();
0989: }
0990: return loggersListProps;
0991: }
0992:
0993: public List getSpecificLogDetails(String componentName,
0994: String componentID, String instance) throws Exception {
0995: logger.log(Level.INFO, "PSFB_CSPFM1014", new Object[] {
0996: componentName, componentID, instance });
0997: validateComponent(componentName);
0998: Properties loggersListProps = getLoggersListProps(
0999: componentName, componentID, instance);
1000: Iterator loggersSetIt = new TreeSet(loggersListProps.keySet())
1001: .iterator();
1002: EnhancedProperties props = getProps(componentName, componentID,
1003: instance);
1004: //list of hashtable
1005: //For each logger there is hashtable
1006: //if a logger does not have any property set specifically, it won't be there in the hashtable
1007: List loggersDetails = new LinkedList();
1008: while (loggersSetIt.hasNext()) {
1009: String logger = (String) loggersSetIt.next();
1010: Hashtable specificLoggerDetails = new Hashtable();
1011: specificLoggerDetails.put(LOGGER_NAME_UI, logger);
1012: if (props.containsKey(logger
1013: + PortalLogManager.LOG_LEVEL_ATTRIBUTE))
1014: specificLoggerDetails.put(LEVEL_UI, props.get(logger
1015: + PortalLogManager.LOG_LEVEL_ATTRIBUTE));
1016: if (props.containsKey(logger
1017: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE))
1018: specificLoggerDetails
1019: .put(
1020: SEPARATE_FILE_UI,
1021: props
1022: .get(logger
1023: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE));
1024: if (props.containsKey(logger
1025: + PortalLogManager.LOG_USE_PARENT_HANDLER))
1026: specificLoggerDetails
1027: .put(
1028: USE_PARENT_UI,
1029: props
1030: .get(logger
1031: + PortalLogManager.LOG_USE_PARENT_HANDLER));
1032: if (props.containsKey(logger
1033: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE))
1034: specificLoggerDetails
1035: .put(
1036: STACKTRACE_UI,
1037: props
1038: .get(logger
1039: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE));
1040:
1041: // Root logger
1042: if (logger.equals(PortalLogManager.DEBUG_ROOT_LOGGER)) {
1043: if (props
1044: .containsKey(PortalLogManager.DEBUG_ROOT_LOGGER
1045: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE)
1046: && props
1047: .get(
1048: PortalLogManager.DEBUG_ROOT_LOGGER
1049: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE)
1050: .equals("true")) {
1051: specificLoggerDetails
1052: .put(SEPARATE_FILE_UI, "false");
1053: specificLoggerDetails.put(USE_PARENT_UI, "true");
1054: } else {
1055: specificLoggerDetails.put(SEPARATE_FILE_UI, "true");
1056: specificLoggerDetails.put(USE_PARENT_UI, "false");
1057: }
1058: }
1059:
1060: // If there is a separate file for the logger, set the UseParent if not present
1061: if (specificLoggerDetails.containsKey(SEPARATE_FILE_UI)
1062: && !specificLoggerDetails
1063: .containsKey(USE_PARENT_UI)) {
1064: specificLoggerDetails.put(USE_PARENT_UI, "false");
1065: }
1066:
1067: loggersDetails.add(specificLoggerDetails);
1068: }
1069: return loggersDetails;
1070: }
1071:
1072: public void setSpecificLogDetails(String componentName,
1073: String componentID, String instance, List loggersDetails)
1074: throws Exception {
1075: logger.log(Level.INFO, "PSFB_CSPFM1002", new Object[] {
1076: componentName, componentID, instance, loggersDetails });
1077: validateComponent(componentName);
1078: EnhancedProperties props = getProps(componentName, componentID,
1079: instance);
1080: Object[] loggersDetailsArray = loggersDetails.toArray();
1081: for (int i = 0; i < loggersDetailsArray.length; i++) {
1082: Hashtable loggerDetails = (Hashtable) loggersDetailsArray[i];
1083: String logger = (String) loggerDetails.get(LOGGER_NAME_UI);
1084: if (loggerDetails.containsKey(LEVEL_UI)) {
1085: // If the LEVEL indicates "Inherit Parent Logger Level",
1086: // then remove the log level attribute only if the logger is not Root Logger
1087: // and ignore if the logger is root logger
1088: String levelValue = (String) loggerDetails
1089: .get(LEVEL_UI);
1090: if (PARENT_LEVEL.equals(levelValue)) {
1091: if (!PortalLogManager.DEBUG_ROOT_LOGGER
1092: .equals(logger)
1093: && !PortalLogManager.DEBUG_ROOT_LOGGER_SEARCH
1094: .equals(logger)) {
1095: props.remove(logger
1096: + PortalLogManager.LOG_LEVEL_ATTRIBUTE);
1097: }
1098: } else {
1099: props.put(logger
1100: + PortalLogManager.LOG_LEVEL_ATTRIBUTE,
1101: levelValue);
1102: }
1103: }
1104:
1105: if (!PortalLogManager.DEBUG_ROOT_LOGGER.equals(logger)) {
1106: // Set the values for separatefile attribute and useparenthandler attribute only if the
1107: // logger is not root logger
1108: if (loggerDetails.containsKey(SEPARATE_FILE_UI))
1109: props
1110: .put(
1111: logger
1112: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE,
1113: (String) loggerDetails
1114: .get(SEPARATE_FILE_UI));
1115: if (loggerDetails.containsKey(USE_PARENT_UI))
1116: props.put(logger
1117: + PortalLogManager.LOG_USE_PARENT_HANDLER,
1118: (String) loggerDetails.get(USE_PARENT_UI));
1119: }
1120:
1121: if (loggerDetails.containsKey(STACKTRACE_UI))
1122: props.put(logger
1123: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE,
1124: (String) loggerDetails.get(STACKTRACE_UI));
1125:
1126: /**
1127: * When the attribute "separatefile" is true, then both the attributes "useparenthandler"
1128: * and "stacktrace" cannot be true.
1129: * If "separatefile=true" and "useparenthandler=true",
1130: * (a)if "stacktrace" is true, set it to false
1131: * (b)if there is no entry for "stacktrace",(it inherits from parent, which can be either
1132: * true or false), set it to "false"
1133: *
1134: * if there is no attribute "separatefile", then there is no need for the "useparent" and
1135: * "stacktrace". Remove these only if the logger is not root logger and the loggers are not search.
1136: */
1137:
1138: if ("true".equals(props.get(logger
1139: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE))) {
1140: if ("true".equals(props.get(logger
1141: + PortalLogManager.LOG_USE_PARENT_HANDLER))) {
1142: if (!"false"
1143: .equals(props
1144: .get(logger
1145: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE))) {
1146: props
1147: .put(
1148: logger
1149: + PortalLogManager.LOG_USE_PARENT_HANDLER,
1150: "false");
1151: }
1152: }
1153: } else if (!logger
1154: .startsWith(PortalLogManager.DEBUG_ROOT_LOGGER_SEARCH)
1155: && !PortalLogManager.DEBUG_ROOT_LOGGER
1156: .equals(logger)) {
1157: props.remove(logger
1158: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE);
1159: props.remove(logger
1160: + PortalLogManager.LOG_USE_PARENT_HANDLER);
1161: props.remove(logger
1162: + PortalLogManager.LOG_STACK_TRACE_ATTRIBUTE);
1163: }
1164: }
1165: String logConfigFileName = getLogConfigFileName(componentName,
1166: componentID, instance);
1167: store(props, componentName, logConfigFileName);
1168: }
1169:
1170: public Hashtable getLogFileNames(String componentName,
1171: String componentID, String instance) throws Exception {
1172: logger.log(Level.INFO, "PSFB_CSPFM1015", new Object[] {
1173: componentName, componentID, instance });
1174: String loggerName = getLoggerName(componentName);
1175: validateInput(componentName, componentID, instance, loggerName);
1176: EnhancedProperties props = getProps(componentName, componentID,
1177: instance);
1178: Hashtable values = new Hashtable();
1179:
1180: // Some loggers might have had separatefile attribute earlier but was deleted, in such cases check the file system
1181: // if there any separate files
1182: String pattern = getLoggerProperty(
1183: props,
1184: loggerName,
1185: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1186: + "."
1187: + DEFAULT_HANDLER
1188: + PortalLogManager.LOG_HANDLER_PATTERN_ATTRIBUTE);
1189: logger.log(Level.FINEST, "PSFB_CSPFM1004", pattern);
1190: StringBuffer buff = new StringBuffer(pattern);
1191: int index = buff.indexOf(PortalLogManager.INSTANCE_ID_PATTERN);
1192: if (index != -1) {
1193: buff.replace(index, index
1194: + PortalLogManager.INSTANCE_ID_PATTERN.length(),
1195: instance);
1196: }
1197:
1198: // Now get the directory containing the log file
1199: index = buff.lastIndexOf("/");
1200: String logDirValue = buff.substring(0, index);
1201: File logDir = new File(logDirValue);
1202: String[] logFileNames = logDir.list(new PortalFilenameFilter());
1203: if (logger.isLoggable(Level.FINEST)) {
1204: StringBuffer sb = new StringBuffer();
1205: for (int i = 0; i < logFileNames.length; i++)
1206: sb.append(logFileNames[i] + ",");
1207: logger.log(Level.FINEST, "PSFB_CSPFM1016", sb);
1208: }
1209:
1210: // Get the loggers that have .separatefile attribute
1211: List loggerNamesWithSeparateFileAttribute = getLoggerNamesWithSeparateFileAttribute(
1212: componentName, props, loggerName);
1213:
1214: List loggerNamesWithSeparateFile = getLoggerNamesWithSeparateFile(
1215: componentName, loggerNamesWithSeparateFileAttribute,
1216: logFileNames);
1217:
1218: values.put(LEVEL_UI, getLoggerProperty(props, loggerName,
1219: PortalLogManager.LOG_LEVEL_ATTRIBUTE));
1220: values.put(LOGFILES_UI, loggerNamesWithSeparateFile);
1221:
1222: return values;
1223: }
1224:
1225: private List getLoggerNamesWithSeparateFileAttribute(
1226: String componentName, EnhancedProperties props,
1227: String rootLoggerName) {
1228: List separateFiles = new LinkedList();
1229: // Looking for separatefile attribute is valid only in case of Portal, as pattern defined for the logger logs to a different place
1230: if (!LoggersList.COMPONENT_PORTAL_INSTANCE
1231: .equals(componentName))
1232: return separateFiles;
1233: Enumeration e = props.propertyNames();
1234: String propertyName, loggerName;
1235: while (e.hasMoreElements()) {
1236: propertyName = (String) e.nextElement();
1237: if (propertyName
1238: .endsWith(PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE)) {
1239: if (props.getProperty(propertyName).equals("true")) {
1240: int index = propertyName
1241: .indexOf(PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE);
1242: loggerName = propertyName.substring(0, index);
1243: if (loggerName
1244: .startsWith(PortalLogManager.DEBUG_ROOT_LOGGER)
1245: && !loggerName.equals(rootLoggerName)) {
1246: int prefixIndex = loggerName
1247: .indexOf(PortalLogManager.DEBUG_COM_SUN_PREFIX);
1248: if (prefixIndex != -1) {
1249: separateFiles
1250: .add(loggerName
1251: .substring(prefixIndex
1252: + PortalLogManager.DEBUG_COM_SUN_PREFIX
1253: .length()));
1254: }
1255: }
1256: }
1257: }
1258: }
1259: return separateFiles;
1260: }
1261:
1262: private List getLoggerNamesWithSeparateFile(String componentName,
1263: List loggerNamesWithSeparateFileAttribute,
1264: String[] logFileNames) {
1265: // The list loggerNamesWithSeparateFileAttribute already contains some loggers that have separatefile attribute
1266: // append to the list
1267: List loggerNamesWithSeparateFile = new LinkedList(
1268: loggerNamesWithSeparateFileAttribute);
1269: String loggerName;
1270: for (int i = 0; i < logFileNames.length; i++) {
1271: // The logFileNames must contain the componentName
1272: if (logFileNames[i].indexOf(componentName) == -1)
1273: continue;
1274:
1275: String[] nameValues = logFileNames[i].split("\\.", -1);
1276: // Check when the sub logger name stops in the nameValues.
1277: // That is the count of sub logger name
1278: StringBuffer loggerNameBuffer = new StringBuffer();
1279: for (int j = 0; j < nameValues.length; j++) {
1280: try {
1281: Integer.parseInt(nameValues[j]);
1282: break;
1283: } catch (Exception e) {
1284: loggerNameBuffer.append(nameValues[j]);
1285: loggerNameBuffer.append(".");
1286: }
1287: }
1288: // As "." is present at the end removed it.
1289: int index = loggerNameBuffer.lastIndexOf(".");
1290: loggerName = loggerNameBuffer.substring(0, index);
1291: if (!loggerNamesWithSeparateFile.contains(loggerName))
1292: loggerNamesWithSeparateFile.add(loggerName);
1293: }
1294: return loggerNamesWithSeparateFile;
1295: }
1296:
1297: public Hashtable getLogRecords(String componentName,
1298: String componentID, String instance,
1299: Hashtable logViewerInputs) throws Exception {
1300:
1301: logger
1302: .log(Level.INFO, "PSFB_CSPFM1003", new Object[] {
1303: componentName, componentID, instance,
1304: logViewerInputs });
1305: String loggerName = getLoggerName(componentName);
1306: validateInput(componentName, componentID, instance, loggerName);
1307: EnhancedProperties props = getProps(componentName, componentID,
1308: instance);
1309: Hashtable values = new Hashtable();
1310:
1311: String selectedLogFileName = (String) logViewerInputs
1312: .get(SELECTED_LOG_FILE_NAME);
1313: logger.log(Level.FINEST, "PSFB_CSPFM1005", selectedLogFileName);
1314:
1315: // the selected log file name does not have debug.com.sun. prefix
1316: // Get the pattern of the selected logger name, if not present it returns the pattern of its parent
1317: String selectedLoggerName = PortalLogManager.DEBUG_COM_SUN_PREFIX
1318: + selectedLogFileName;
1319: String pattern = getLoggerProperty(
1320: props,
1321: selectedLoggerName,
1322: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1323: + "."
1324: + DEFAULT_HANDLER
1325: + PortalLogManager.LOG_HANDLER_PATTERN_ATTRIBUTE);
1326: logger.log(Level.FINEST, "PSFB_CSPFM1004", pattern);
1327:
1328: StringBuffer buff = new StringBuffer(pattern);
1329: int index = buff.indexOf(PortalLogManager.INSTANCE_ID_PATTERN);
1330: if (index != -1) {
1331: buff.replace(index, index
1332: + PortalLogManager.INSTANCE_ID_PATTERN.length(),
1333: instance);
1334: }
1335:
1336: // Now get the directory containing the log file
1337: index = buff.lastIndexOf("/");
1338: String logDirValue = buff.substring(0, index);
1339: File logDir = new File(logDirValue);
1340: File[] logFiles = logDir
1341: .listFiles(LoggersList.COMPONENT_SEARCH_INSTANCE
1342: .equals(componentName) ? (FilenameFilter) new SearchLoggerFilenameFilter(
1343: selectedLogFileName)
1344: : (FilenameFilter) new PortalLoggerFilenameFilter(
1345: selectedLogFileName));
1346:
1347: // Get the log viewer inputs
1348: Date fromDateTime = null;
1349: Date toDateTime = null;
1350: boolean onlyDate = true;
1351: Boolean mostRecent = (Boolean) logViewerInputs
1352: .get(SELECTED_MOST_RECENT_UI);
1353: // If its not MostRecent, it must be Specific Range, so get the date and time
1354: // values
1355: if (!mostRecent.booleanValue()) {
1356: String fromDateValue, toDateValue, fromTimeValue, toTimeValue;
1357: fromDateValue = (String) logViewerInputs
1358: .get(SELECTED_SPECIFIC_RANGE_FROM_DATE_UI);
1359: toDateValue = (String) logViewerInputs
1360: .get(SELECTED_SPECIFIC_RANGE_TO_DATE_UI);
1361: fromTimeValue = (String) logViewerInputs
1362: .get(SELECTED_SPECIFIC_RANGE_FROM_TIME_UI);
1363: toTimeValue = (String) logViewerInputs
1364: .get(SELECTED_SPECIFIC_RANGE_TO_TIME_UI);
1365:
1366: // If both times are null, use only date
1367: if (fromTimeValue == null && toTimeValue == null) {
1368: fromDateTime = inputDateFormatter.parse(fromDateValue);
1369: toDateTime = inputDateFormatter.parse(toDateValue);
1370: onlyDate = true;
1371: } else {
1372: // Both times may be present or only toTime may be present
1373: if (fromTimeValue == null)
1374: fromTimeValue = "00:00:00.000";
1375: String fromDateTimeValue = fromDateValue + "T"
1376: + fromTimeValue;
1377: String toDateTimeValue = toDateValue + "T"
1378: + toTimeValue;
1379: fromDateTime = inputDateTimeFormatter
1380: .parse(fromDateTimeValue);
1381: toDateTime = inputDateTimeFormatter
1382: .parse(toDateTimeValue);
1383: onlyDate = false;
1384: }
1385: }
1386:
1387: String levelValue = (String) logViewerInputs.get(LEVEL_UI);
1388: Boolean includeMoreSevere = (Boolean) logViewerInputs
1389: .get(INCLUDE_MORE_SEVERE_UI);
1390:
1391: Vector relevantFiles = getRelevantFiles(selectedLogFileName,
1392: logFiles, mostRecent.booleanValue());
1393: List logRecords = new LinkedList();
1394:
1395: logger.log(Level.FINER, "PSFB_CSPFM1017", relevantFiles);
1396:
1397: // As portal.0.0.log is current and portal.0.1.log is next and files are returned in that order,
1398: // read it in the reverse
1399: for (int i = relevantFiles.size() - 1; i >= 0; i--) {
1400:
1401: BufferedReader reader = new BufferedReader(
1402: new InputStreamReader(new FileInputStream(
1403: (File) relevantFiles.get(i))));
1404:
1405: String line;
1406: boolean recordStart = false;
1407: boolean recordEnd = false;
1408: Vector logRecordFields;
1409: StringBuffer lineBuffer = new StringBuffer();
1410: while (true) {
1411: line = reader.readLine();
1412: if (line == null)
1413: break;
1414: if (line.trim().equals(""))
1415: continue;
1416: // It means there are more lines in the message. Retain the new line
1417: if (recordStart && !recordEnd) {
1418: lineBuffer
1419: .append(PortalLogFormatter.LINE_SEPARATOR);
1420: }
1421: lineBuffer.append(line);
1422:
1423: if (line
1424: .startsWith(PortalLogFormatter.RECORD_BEGIN_MARKER))
1425: recordStart = true;
1426: if (recordStart
1427: && line
1428: .endsWith(PortalLogFormatter.RECORD_END_MARKER))
1429: recordEnd = true;
1430: if (recordEnd) {
1431: try {
1432: logRecordFields = getLogRecord(lineBuffer
1433: .toString(), mostRecent.booleanValue(),
1434: fromDateTime, toDateTime, onlyDate,
1435: levelValue, includeMoreSevere
1436: .booleanValue());
1437: } catch (DateExceededException e) {
1438: break;
1439: }
1440: if (!logRecordFields.isEmpty())
1441: logRecords.add(logRecordFields);
1442: recordStart = false;
1443: recordEnd = false;
1444: lineBuffer = new StringBuffer();
1445: }
1446: }
1447: }
1448:
1449: values.put(LOGFILES_DIR_UI, logDirValue);
1450:
1451: // If Most Recent is selected send only limited records,
1452: // specified by the key TOTAL_LOG_RECORDS_FOR_MOST_RECENT
1453: if (mostRecent.booleanValue()) {
1454: Integer rowCount = (Integer) logViewerInputs
1455: .get(TOTAL_LOG_RECORDS_FOR_MOST_RECENT);
1456: values.put(LOGRECORDS_UI, getLogRecordsForMostRecent(
1457: logRecords, rowCount.intValue()));
1458: } else {
1459: values.put(LOGRECORDS_UI, logRecords);
1460: }
1461:
1462: return values;
1463: }
1464:
1465: public Hashtable getLoggerDetails(String componentType,
1466: String componentID, String instance, String loggerName)
1467: throws Exception {
1468: Hashtable detailsTable = new Hashtable();
1469: validateComponent(componentType);
1470: EnhancedProperties props = getProps(getLogConfigFileName(
1471: componentType, componentID, instance));
1472: LoggerDetails details = getLoggerDetails(componentType,
1473: loggerName, props);
1474: detailsTable.put(PortalLogConfigurator.LOGGER_NAME_UI,
1475: loggerName);
1476: detailsTable.put(PortalLogConfigurator.LEVEL_UI, details
1477: .getLevel());
1478: detailsTable.put(PortalLogConfigurator.STACKTRACE_UI, details
1479: .getStackTraceValue());
1480: detailsTable.put(PortalLogConfigurator.USE_PARENT_UI, details
1481: .isLogToParent());
1482: detailsTable
1483: .put(
1484: PortalLogConfigurator.SEPARATE_FILE_UI,
1485: props
1486: .containsKey(loggerName
1487: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE) ? props
1488: .get(loggerName
1489: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE)
1490: : "false");
1491: detailsTable
1492: .put(
1493: PortalLogConfigurator.PATTERN_UI,
1494: getLoggerProperty(
1495: props,
1496: loggerName,
1497: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1498: + "."
1499: + DEFAULT_HANDLER
1500: + PortalLogManager.LOG_HANDLER_PATTERN_ATTRIBUTE));
1501: detailsTable.put(HANDLER_UI, getLoggerProperty(props,
1502: loggerName, PortalLogManager.LOG_HANDLER_ATTRIBUTE));
1503: detailsTable
1504: .put(
1505: LIMIT_UI,
1506: getLoggerProperty(
1507: props,
1508: loggerName,
1509: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1510: + "."
1511: + DEFAULT_HANDLER
1512: + PortalLogManager.LOG_HANDLER_LIMIT_ATTRIBUTE));
1513: detailsTable
1514: .put(
1515: COUNT_UI,
1516: getLoggerProperty(
1517: props,
1518: loggerName,
1519: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1520: + "."
1521: + DEFAULT_HANDLER
1522: + PortalLogManager.LOG_HANDLER_COUNT_ATTRIBUTE));
1523: detailsTable
1524: .put(
1525: APPEND_UI,
1526: getLoggerProperty(
1527: props,
1528: loggerName,
1529: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1530: + "."
1531: + DEFAULT_HANDLER
1532: + PortalLogManager.LOG_HANDLER_APPEND_ATTRIBUTE));
1533: detailsTable
1534: .put(
1535: FILTER_UI,
1536: getLoggerProperty(
1537: props,
1538: loggerName,
1539: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1540: + "."
1541: + DEFAULT_HANDLER
1542: + PortalLogManager.LOG_HANDLER_FILTER_ATTRIBUTE));
1543: detailsTable
1544: .put(
1545: FORMATTER_UI,
1546: getLoggerProperty(
1547: props,
1548: loggerName,
1549: PortalLogManager.LOG_HANDLER_ATTRIBUTE
1550: + "."
1551: + DEFAULT_HANDLER
1552: + PortalLogManager.LOG_HANDLER_FORMATTER_ATTRIBUTE));
1553: if (props.containsKey(loggerName
1554: + PortalLogManager.LOG_HANDLER_ATTRIBUTE + "."
1555: + DEFAULT_HANDLER
1556: + PortalLogManager.LOG_HANDLER_FORMATTER_ATTRIBUTE)
1557: || props
1558: .containsKey(loggerName
1559: + PortalLogManager.LOG_HANDLER_ATTRIBUTE
1560: + "."
1561: + DEFAULT_HANDLER
1562: + PortalLogManager.LOG_HANDLER_PATTERN_ATTRIBUTE)
1563: || props.containsKey(loggerName
1564: + PortalLogManager.LOG_HANDLER_ATTRIBUTE)) {
1565: detailsTable.put(SEPARATE_FILE_UI, "true");
1566: }
1567: if ((props.containsKey(loggerName
1568: + PortalLogManager.LOG_SEPARATE_FILE_ATTRIBUTE) || (detailsTable
1569: .containsKey(SEPARATE_FILE_UI) && "true"
1570: .equals((String) detailsTable.get(SEPARATE_FILE_UI))))
1571: && !props.containsKey(loggerName
1572: + PortalLogManager.LOG_USE_PARENT_HANDLER)) {
1573: detailsTable.put(USE_PARENT_UI, "false");
1574: }
1575: if (PortalLogManager.DEBUG_ROOT_LOGGER.equals(loggerName)
1576: || PortalLogManager.DEBUG_ROOT_LOGGER_SEARCH
1577: .equals(loggerName)) {
1578: if (props.containsKey(loggerName
1579: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE)
1580: && props
1581: .get(
1582: loggerName
1583: + PortalLogManager.LOG_TO_SERVER_ATTRIBUTE)
1584: .equals("true")) {
1585: detailsTable.put(SEPARATE_FILE_UI, "false");
1586: detailsTable.put(USE_PARENT_UI, "true");
1587: } else {
1588: detailsTable.put(SEPARATE_FILE_UI, "true");
1589: detailsTable.put(USE_PARENT_UI, "false");
1590: }
1591: }
1592: return detailsTable;
1593: }
1594:
1595: private List getLogRecordsForMostRecent(List logRecords,
1596: int totalLogRecords) {
1597: List tempLogRecords = new LinkedList();
1598: int size = logRecords.size();
1599: int start = size - totalLogRecords;
1600: if (start < 0)
1601: start = 0;
1602: // Send all the records in Reverse Chronological order
1603: for (int i = start; i < size; i++) {
1604: tempLogRecords.add(logRecords.get(i));
1605: }
1606: return tempLogRecords;
1607: }
1608:
1609: private Vector getRelevantFiles(String rootLogger, File[] logFiles,
1610: boolean mostRecent) {
1611:
1612: Vector relevantFiles = new Vector();
1613: String logFileName;
1614: for (int i = 0; i < logFiles.length; i++) {
1615: logFileName = logFiles[i].getName();
1616: if (logFileName.startsWith(rootLogger)) {
1617: if (mostRecent) {
1618: // The pattern must be <something>.%u.%g.log
1619: // Get the recent file. The file with %g=0 is the recent file
1620: String[] values = logFileName.split("\\.", 0);
1621: int gIndex = values.length - 2; // last but one, i.e %g is before .log
1622: int gValue = Integer.parseInt(values[gIndex]);
1623: if (gValue == 0) {
1624: relevantFiles.add(logFiles[i]);
1625: break;
1626: } else {
1627: logger.log(Level.INFO, "PSFB_CSPFM1018", String
1628: .valueOf(gValue));
1629: }
1630: } else {
1631: relevantFiles.add(logFiles[i]);
1632: }
1633: }
1634: }
1635: return relevantFiles;
1636: }
1637:
1638: private static Vector getLogRecord(String line, boolean mostRecent,
1639: Date fromDateTime, Date toDateTime, boolean onlyDate,
1640: String levelValue, boolean includeMoreSevere)
1641: throws Exception {
1642: Vector logRecordFields = new Vector();
1643: // Values should be same as that in LogRecordBean
1644: // 0 = timestamp
1645: // 1 = log level
1646: // 2 = loggerName
1647: // 3 = name value pairs
1648: // 4 = message
1649: int startRecordIndex = line
1650: .indexOf(PortalLogFormatter.RECORD_BEGIN_MARKER);
1651: int endRecordIndex = line
1652: .indexOf(PortalLogFormatter.RECORD_END_MARKER);
1653: String logRecordLine = line.substring(startRecordIndex
1654: + PortalLogFormatter.RECORD_BEGIN_MARKER.length(),
1655: endRecordIndex);
1656: StringTokenizer tokens = new StringTokenizer(logRecordLine,
1657: PortalLogFormatter.FIELD_SEPARATOR);
1658:
1659: // For first five fields | is the delimiter and its guaranteed that the token itself does
1660: // not have the delimiter. But that is not the case with the sixth field which is the message.
1661: // So any tokens after 6th field is collated and made the sixth element in the Vector.
1662: String datetime = tokens.nextToken();
1663: String logLevel = tokens.nextToken();
1664: String productId = tokens.nextToken(); //DO NOT DELETE THIS EVEN IF NOT USED
1665: String loggerName = tokens.nextToken();
1666: String nameValuePairs = tokens.nextToken();
1667: StringBuffer messageBuffer = new StringBuffer();
1668: while (tokens.hasMoreTokens()) {
1669: messageBuffer.append(tokens.nextToken());
1670: }
1671:
1672: Date logDateTime = logDateTimeFormatter.parse(datetime);
1673:
1674: if (!mostRecent) {
1675: // Check date
1676: if (onlyDate) {
1677: // Compare only dates
1678: int index = datetime
1679: .indexOf(PortalLogFormatter.DATE_TIME_DELIMITER);
1680: String dateValue = datetime.substring(0, index);
1681: Date logDate = logDateFormatter.parse(dateValue);
1682: if (logDate.compareTo(fromDateTime) < 0)
1683: return logRecordFields;
1684:
1685: if (logDate.compareTo(toDateTime) > 0)
1686: throw new DateExceededException(); // should throw exception to stop processing
1687: } else {
1688: if (logDateTime.compareTo(fromDateTime) < 0)
1689: return logRecordFields;
1690:
1691: if (logDateTime.compareTo(toDateTime) > 0)
1692: throw new DateExceededException(); // should throw exception to stop processing
1693: }
1694: }
1695:
1696: // Check level
1697: int inputLevel = Level.parse(levelValue).intValue();
1698: int currentLevel = Level.parse(logLevel).intValue();
1699: if (currentLevel >= inputLevel) {
1700: if (!includeMoreSevere && currentLevel != inputLevel)
1701: return logRecordFields;
1702:
1703: logRecordFields.add(logDateTime); // TIMESTAMP_INDEX);
1704: logRecordFields.add(logLevel); // LOG_LEVEL_INDEX
1705: logRecordFields.add(loggerName); // LOGGER_NAME_INDEX
1706: logRecordFields.add(nameValuePairs); // NAME_VALUE_PAIR_INDEX
1707: logRecordFields.add(messageBuffer.toString()); //MESSAGE_INDEX
1708: }
1709: return logRecordFields;
1710: }
1711: }
1712:
1713: /**
1714: * Used to Sort the logger names in the descending order.
1715: */
1716: class LoggerComparator implements Comparator {
1717:
1718: public int compare(Object o1, Object o2) {
1719: String s1 = (String) o1;
1720: String s2 = (String) o2;
1721: return s2.compareTo(s1);
1722: }
1723: }
1724:
1725: /**
1726: * Used to Filter only those files that start with "portal."
1727: */
1728:
1729: class PortalFilenameFilter implements FilenameFilter {
1730:
1731: /**
1732: * return true if name starts with "portal." and does not end with .lck
1733: *
1734: * @param dir
1735: * @param name
1736: * @return
1737: */
1738: public boolean accept(File dir, String name) {
1739: return (name.indexOf("portal.") != -1)
1740: && !name.endsWith(".lck");
1741: }
1742: }
1743:
1744: class SearchLoggerFilenameFilter implements FilenameFilter {
1745: private String loggerName;
1746:
1747: SearchLoggerFilenameFilter(String loggerName) {
1748: this .loggerName = loggerName;
1749: }
1750:
1751: public boolean accept(File dir, String name) {
1752: return (name.indexOf(loggerName + ".") != -1 && !name
1753: .endsWith(".lck"));
1754: }
1755:
1756: }
1757:
1758: /**
1759: * Used to Filter only those files that start with the input loggerName.
1760: */
1761:
1762: class PortalLoggerFilenameFilter implements FilenameFilter {
1763:
1764: private String pattern;
1765:
1766: PortalLoggerFilenameFilter(String loggerName) {
1767: pattern = loggerName + "\\.[0-9]+\\.[0-9]+\\.log";
1768: }
1769:
1770: /**
1771: * return true if name starts with "portal." and does not end with .lck
1772: *
1773: * @param dir
1774: * @param name
1775: * @return
1776: */
1777: public boolean accept(File dir, String name) {
1778: if ((name.indexOf("portal.") != -1) && !name.endsWith(".lck")) {
1779: return Pattern.matches(pattern, name);
1780: }
1781: return false;
1782: }
1783: }
1784:
1785: /**
1786: * Used to indicate that the date obtained from the log file is beyond the input date obtained
1787: * from the UI.
1788: */
1789: class DateExceededException extends Exception {
1790: }
|