Created
April 8, 2011 09:48
-
-
Save anonomis/909570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.net.URI; | |
import java.util.regex.Pattern; | |
import javax.swing.JApplet; | |
import javax.swing.JScrollPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
public class LogReader extends JApplet { | |
public LogReader() { | |
String data[][] = {}; | |
String col[] = { "level", "date", "package", "class", "method", "text" }; | |
DefaultTableModel model = new DefaultTableModel(data, col); | |
final JTable table = new JTable(model); | |
table.setSize(1100, 650); | |
JScrollPane pane = new JScrollPane(table); | |
pane.setSize(1100, 650); | |
table.getColumnModel().getColumn(0).setMaxWidth(35); | |
table.getColumnModel().getColumn(1).setMaxWidth(65); | |
table.getColumnModel().getColumn(2).setPreferredWidth(128); | |
table.getColumnModel().getColumn(2).setResizable(false); | |
table.getColumnModel().getColumn(3).setPreferredWidth(128); | |
table.getColumnModel().getColumn(4).setPreferredWidth(128); | |
table.getColumnModel().getColumn(5).setPreferredWidth(1000); | |
table.getColumnModel().getColumn(5).setPreferredWidth(1000); | |
this.add(pane); | |
Runnable d = new Runnable() { | |
@Override | |
public void run() { | |
try { | |
File f = new File( | |
new URI( | |
"file:///home...")); | |
long lengthRead = 0; | |
while (true != false) { | |
if (f.length() > lengthRead) { | |
BufferedReader br = new BufferedReader(new FileReader(f)); | |
DefaultTableModel model = (DefaultTableModel) table.getModel(); | |
while (br.ready()) { | |
String readLine = br.readLine(); | |
while (br.ready()) { | |
if (readLine.startsWith("2011")) { | |
String time = readLine.subSequence(12, 20).toString(); | |
String rest = readLine.substring(20); | |
Pattern p = Pattern.compile("[A-Z]"); | |
String[] split = p.split(rest); | |
String packagee = split[0].substring(split[0].indexOf(".") + 1); | |
String[] split2 = rest.substring(split[0].length()).split(" "); | |
String clazz = split2[0]; | |
String method = split2[1]; | |
readLine = br.readLine(); | |
split = readLine.split(":"); | |
String level = split[0]; | |
String text = split[1]; | |
for (String string : split) { | |
text = text.concat(string); | |
} | |
model.insertRow(0, new Object[] { level, time, packagee, clazz, method, text }); | |
readLine = br.readLine(); | |
while (!readLine.startsWith("2011") && br.ready()) { | |
text = readLine; | |
readLine = br.readLine(); | |
model.insertRow(0, new Object[] { "", "", "", "", "", text }); | |
} | |
} else { | |
throw new RuntimeException("parse error :'" + readLine + "'"); | |
} | |
} | |
} | |
lengthRead = f.length(); | |
} | |
Thread.sleep(10L); | |
} | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
}; | |
Thread th = new Thread(d); | |
th.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment