Fields Summary |
---|
public static final String | RECORD_DELIMITER |
public static final String | ATTRIBUTE_DELIMITER |
public static final String | DATE_DELIMITER |
public static final String | THREAD_DELIMITER |
public static final String | CATEGORY_DELIMITER |
public static final String | LOCATION_DELIMITER |
public static final String | MESSAGE_DELIMITER |
public static final String | PRIORITY_DELIMITER |
public static final String | NDC_DELIMITER |
private static SimpleDateFormat | _sdf |
private LogBrokerMonitor | _monitor |
LogFactor5LoadingDialog | _loadDialog |
private InputStream | _in |
Methods Summary |
---|
private org.apache.log4j.lf5.LogRecord | createLogRecord(java.lang.String record)
if (record == null || record.trim().length() == 0) {
return null;
}
LogRecord lr = new Log4JLogRecord();
lr.setMillis(parseDate(record));
lr.setLevel(parsePriority(record));
lr.setCategory(parseCategory(record));
lr.setLocation(parseLocation(record));
lr.setThreadDescription(parseThread(record));
lr.setNDC(parseNDC(record));
lr.setMessage(parseMessage(record));
lr.setThrownStackTrace(parseThrowable(record));
return lr;
|
private void | destroyDialog()
_loadDialog.hide();
_loadDialog.dispose();
|
protected void | displayError(java.lang.String message)
LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
_monitor.getBaseFrame(), message);
|
private java.lang.String | getAttribute(int index, java.lang.String record)
int start = record.lastIndexOf(ATTRIBUTE_DELIMITER, index - 1);
if (start == -1) {
return record.substring(0, index);
}
start = record.indexOf("]", start);
return record.substring(start + 1, index).trim();
|
private java.lang.String | loadLogFile(java.io.InputStream stream)Loads a log file from a web server into the LogFactor5 GUI.
BufferedInputStream br = new BufferedInputStream(stream);
int count = 0;
int size = br.available();
StringBuffer sb = null;
if (size > 0) {
sb = new StringBuffer(size);
} else {
sb = new StringBuffer(1024);
}
while ((count = br.read()) != -1) {
sb.append((char) count);
}
br.close();
br = null;
return sb.toString();
|
public void | parse(org.apache.log4j.lf5.viewer.LogBrokerMonitor monitor)Starts a new thread to parse the log file and create a LogRecord.
See run().
_monitor = monitor;
Thread t = new Thread(this);
t.start();
|
private java.lang.String | parseAttribute(java.lang.String name, java.lang.String record)
int index = record.indexOf(name);
if (index == -1) {
return null;
}
return getAttribute(index, record);
|
private java.lang.String | parseCategory(java.lang.String record)
return parseAttribute(CATEGORY_DELIMITER, record);
|
private long | parseDate(java.lang.String record)
try {
String s = parseAttribute(DATE_DELIMITER, record);
if (s == null) {
return 0;
}
Date d = _sdf.parse(s);
return d.getTime();
} catch (ParseException e) {
return 0;
}
|
private java.lang.String | parseLocation(java.lang.String record)
return parseAttribute(LOCATION_DELIMITER, record);
|
private java.lang.String | parseMessage(java.lang.String record)
return parseAttribute(MESSAGE_DELIMITER, record);
|
private java.lang.String | parseNDC(java.lang.String record)
return parseAttribute(NDC_DELIMITER, record);
|
private org.apache.log4j.lf5.LogLevel | parsePriority(java.lang.String record)
String temp = parseAttribute(PRIORITY_DELIMITER, record);
if (temp != null) {
try {
return LogLevel.valueOf(temp);
} catch (LogLevelFormatException e) {
return LogLevel.DEBUG;
}
}
return LogLevel.DEBUG;
|
private java.lang.String | parseThread(java.lang.String record)
return parseAttribute(THREAD_DELIMITER, record);
|
private java.lang.String | parseThrowable(java.lang.String record)
return getAttribute(record.length(), record);
|
public void | run()Parses the file and creates new log records and adds the record
to the monitor.
int index = 0;
int counter = 0;
LogRecord temp;
boolean isLogFile = false;
_loadDialog = new LogFactor5LoadingDialog(
_monitor.getBaseFrame(), "Loading file...");
try {
String logRecords = loadLogFile(_in);
while ((counter = logRecords.indexOf(RECORD_DELIMITER, index)) != -1) {
temp = createLogRecord(logRecords.substring(index, counter));
isLogFile = true;
if (temp != null) {
_monitor.addMessage(temp);
}
index = counter + RECORD_DELIMITER.length();
}
if (index < logRecords.length() && isLogFile) {
temp = createLogRecord(logRecords.substring(index));
if (temp != null) {
_monitor.addMessage(temp);
}
}
if (isLogFile == false) {
throw new RuntimeException("Invalid log file format");
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
destroyDialog();
}
});
} catch (RuntimeException e) {
destroyDialog();
displayError("Error - Invalid log file format.\nPlease see documentation"
+ " on how to load log files.");
} catch (IOException e) {
destroyDialog();
displayError("Error - Unable to load log file!");
}
_in = null;
|