001: package com.sun.portal.search.admin.mbeans.tasks;
002:
003: import java.io.*;
004: import java.util.*;
005: import java.util.logging.*;
006: import java.net.*;
007: import java.lang.*;
008: import java.text.*;
009:
010: import com.sun.portal.admin.server.mbeans.PSResource;
011: import com.sun.portal.admin.common.context.PortalDomainContext;
012: import com.sun.portal.admin.common.context.PSConfigContext;
013: import com.sun.portal.admin.common.PSMBeanException;
014:
015: import com.sun.portal.search.admin.CSConfig;
016: import com.sun.portal.search.admin.mbeans.*;
017:
018: public class Report {
019:
020: public static final String FILTER_LOG = "filter";
021: public static final String RD_MANAGER_LOG = "rdmanager";
022: public static final String RDM_LOG = "rdm";
023: public static final String RDM_SERVER_LOG = "rdmserver";
024: public static final String ROBOT_LOG = "robot";
025: public static final String SEARCH_ENGINE_LOG = "searchengine";
026:
027: private String searchServerRoot = null;
028: private static Logger logger = null;
029:
030: public Report(String searchServerRoot, Logger logger) {
031: this .searchServerRoot = searchServerRoot;
032: this .logger = logger;
033: }
034:
035: public String get(String logType, int lineLimit)
036: throws PSMBeanException {
037: StringBuffer sb = new StringBuffer();
038:
039: String logFileName = "";
040: if (logType.equals(FILTER_LOG)) {
041: logFileName = searchServerRoot + File.separator + "logs"
042: + File.separator + "filter.log";
043: } else if (logType.equals(RD_MANAGER_LOG)) {
044: logFileName = searchServerRoot + File.separator + "logs"
045: + File.separator + "rdmgr.0.0.log";
046: } else if (logType.equals(ROBOT_LOG)) {
047: logFileName = searchServerRoot + File.separator + "logs"
048: + File.separator + "robot.log";
049: } else if (logType.equals(SEARCH_ENGINE_LOG)) {
050: logFileName = searchServerRoot + File.separator + "logs"
051: + File.separator + "searchengine.log";
052: } else if (logType.equals(RDM_LOG)) {
053: logFileName = searchServerRoot + File.separator + "logs"
054: + File.separator + "rdm.0.0.log";
055: } else if (logType.equals(RDM_SERVER_LOG)) {
056: logFileName = searchServerRoot + File.separator + "logs"
057: + File.separator + "rdmserver.0.0.log";
058: } else {
059: String message = "Unknown log type - " + logType;
060: Object tokens[] = { message };
061: logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
062: throw new PSMBeanException("PSALI_CSPACCSH0001");
063: }
064:
065: try {
066: File f = new File(logFileName);
067: if (f.exists()) {
068: RandomAccessFile raf = new RandomAccessFile(f, "r");
069: if (raf.length() > 0) {
070: raf.seek(raf.length() - 1);
071:
072: byte[] buffer = new byte[1];
073:
074: int lines = (lineLimit > 0) ? lineLimit : 1;
075: while (lines >= 0) {
076: long currentOffset = raf.getFilePointer();
077: raf.readFully(buffer);
078: if (buffer[0] == '\n') {
079: if (lineLimit > 0) {
080: lines -= 1;
081: }
082: if (lines >= 0) {
083: sb.insert(0, "\n");
084: }
085: } else if (buffer[0] != '\r') {
086: sb.insert(0, (char) buffer[0]);
087: }
088: if (currentOffset == 0) {
089: break;
090: } else {
091: raf.seek(currentOffset - 1);
092: }
093: }
094: int length = sb.length();
095: if (length > 0 && sb.charAt(length - 1) != '\n') {
096: sb.append("\n");
097: }
098: }
099: }
100: } catch (Exception e) {
101: logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
102: throw new PSMBeanException("PSALI_CSPACCSH0001", e
103: .toString(), e);
104: }
105:
106: return sb.toString();
107: }
108:
109: }
|