The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
LogFileParser.java
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*/
package org.apache.log4j.lf5.util;
import org.apache.log4j.lf5.Log4JLogRecord;
import org.apache.log4j.lf5.LogLevel;
import org.apache.log4j.lf5.LogLevelFormatException;
import org.apache.log4j.lf5.LogRecord;
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
import org.apache.log4j.lf5.viewer.LogFactor5ErrorDialog;
import org.apache.log4j.lf5.viewer.LogFactor5LoadingDialog;
import javax.swing.*;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Provides utility methods for input and output streams.
*
* @author Brad Marlborough
* @author Richard Hurst
*/
// Contributed by ThoughtWorks Inc.
public class LogFileParser implements Runnable {
//--------------------------------------------------------------------------
// Constants:
//--------------------------------------------------------------------------
public static final String RECORD_DELIMITER = "[slf5s.start]";
public static final String ATTRIBUTE_DELIMITER = "[slf5s.";
public static final String DATE_DELIMITER = ATTRIBUTE_DELIMITER + "DATE]";
public static final String THREAD_DELIMITER = ATTRIBUTE_DELIMITER + "THREAD]";
public static final String CATEGORY_DELIMITER = ATTRIBUTE_DELIMITER + "CATEGORY]";
public static final String LOCATION_DELIMITER = ATTRIBUTE_DELIMITER + "LOCATION]";
public static final String MESSAGE_DELIMITER = ATTRIBUTE_DELIMITER + "MESSAGE]";
public static final String PRIORITY_DELIMITER = ATTRIBUTE_DELIMITER + "PRIORITY]";
public static final String NDC_DELIMITER = ATTRIBUTE_DELIMITER + "NDC]";
//--------------------------------------------------------------------------
// Protected Variables:
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Private Variables:
//--------------------------------------------------------------------------
private static SimpleDateFormat _sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss,S");
private LogBrokerMonitor _monitor;
LogFactor5LoadingDialog _loadDialog;
private InputStream _in = null;
//--------------------------------------------------------------------------
// Constructors:
//--------------------------------------------------------------------------
public LogFileParser(File file) throws IOException,
FileNotFoundException {
this(new FileInputStream(file));
}
public LogFileParser(InputStream stream) throws IOException {
_in = stream;
}
//--------------------------------------------------------------------------
// Public Methods:
//--------------------------------------------------------------------------
/**
* Starts a new thread to parse the log file and create a LogRecord.
* See run().
* @param LogBrokerMonitor
*/
public void parse(LogBrokerMonitor monitor) throws RuntimeException {
_monitor = monitor;
Thread t = new Thread(this);
t.start();
}
/**
* Parses the file and creates new log records and adds the record
* to the monitor.
*/
public void run() {
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;
}
//--------------------------------------------------------------------------
// Protected Methods:
//--------------------------------------------------------------------------
protected void displayError(String message) {
LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
_monitor.getBaseFrame(), message);
}
//--------------------------------------------------------------------------
// Private Methods:
//--------------------------------------------------------------------------
private void destroyDialog() {
_loadDialog.hide();
_loadDialog.dispose();
}
/**
* Loads a log file from a web server into the LogFactor5 GUI.
*/
private String loadLogFile(InputStream stream) throws IOException {
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();
}
private String parseAttribute(String name, String record) {
int index = record.indexOf(name);
if (index == -1) {
return null;
}
return getAttribute(index, record);
}
private long parseDate(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 LogLevel parsePriority(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 String parseThread(String record) {
return parseAttribute(THREAD_DELIMITER, record);
}
private String parseCategory(String record) {
return parseAttribute(CATEGORY_DELIMITER, record);
}
private String parseLocation(String record) {
return parseAttribute(LOCATION_DELIMITER, record);
}
private String parseMessage(String record) {
return parseAttribute(MESSAGE_DELIMITER, record);
}
private String parseNDC(String record) {
return parseAttribute(NDC_DELIMITER, record);
}
private String parseThrowable(String record) {
return getAttribute(record.length(), record);
}
private LogRecord createLogRecord(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 String getAttribute(int index, 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();
}
//--------------------------------------------------------------------------
// Nested Top-Level Classes or Interfaces
//--------------------------------------------------------------------------
}