/hg/icedtea-web: Implemented xml logging backend
jvanek at icedtea.classpath.org
jvanek at icedtea.classpath.org
Mon Jun 11 11:49:46 PDT 2012
changeset ce4f95c56f02 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=ce4f95c56f02
author: Jiri Vanek <jvanek at redhat.com>
date: Mon Jun 11 20:53:23 2012 +0200
Implemented xml logging backend
diffstat:
ChangeLog | 35 +
Makefile.am | 19 +-
tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java | 2 +-
tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java | 20 +-
tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java | 255 +++++++++-
tests/report-styles/index.js | 82 +++
tests/report-styles/jreport.xsl | 24 +-
tests/report-styles/logs.xsl | 153 ++++++
tests/report-styles/output.css | 7 +
tests/report-styles/report.css | 5 +
10 files changed, 554 insertions(+), 48 deletions(-)
diffs (truncated from 866 to 500 lines):
diff -r 1ecbf90070ad -r ce4f95c56f02 ChangeLog
--- a/ChangeLog Mon Jun 11 10:36:09 2012 -0400
+++ b/ChangeLog Mon Jun 11 20:53:23 2012 +0200
@@ -1,3 +1,38 @@
+2012-06-11 Jiri Vanek <jvanek at redhat.com>
+
+ Implemented xml logging backend
+ * Makefile.am: (stamps/run-netx-unit-tests.stamp) and
+ (stamps/run-netx-dist-tests.stamp) removed redirection of streams as
+ logging is now done in ServerAccess tests extensions
+ added xsltproc execution above generated xml log
+ xsltproc generating results html files is now receiving result of above
+ as parameter
+ * tests/report-styles/jreport.xsl: log parameter is now accepted, and
+ if set, then all tests are linking into specified file to show the log
+ * tests/report-styles/report.css: added styles for new links
+ * tests/report-styles/index.js: new functions to work for result of below sheet
+ * tests/report-styles/logs.xsl: new file, sheet to convert xml log to html file
+ * tests/report-styles/output.css: new file, styles of above html file
+ * tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java:
+ * tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java:
+ * tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java:
+ Tests', server's and ProcessAssasin's logs are now redirected to bottleneck
+ * tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java:
+ (LOGS_REPRINT) flag for debugging purposes, will enable reprinting to
+ stdout/err again
+ (DEFAULT_LOG_FILE ) default name of xml output
+ (DEFAULT_STDERR_FILE)(DEFAULT_STDOUT_FILE)(DEFAULT_STDLOGS_FILE) default
+ values of plain text output files
+ (*ELEMENT) and( (*ATTRIBUTE) variables keeping repeated names of xml
+ output parts
+ (writeXmlLog) method called from Sytsem.hook to save xml log
+ (addToXmlLog) method to record item to xml structure
+ (TestsLogs) and (LogItem) inner classes to keep logging information
+ (log) is now reprinting message with id to std out/err dependently on
+ (LOGS_REPRINT) but always to internal streams, possilbe exception is thrown
+ (logException) new method, shortcut to log exception in same way as message
+ (getTestMethod) now can handle methods inside ServerAccess class too
+
2012-06-11 Adam Domurad <adomurad at redhat.com>
* NEWS: Added mention of fixing PR518
diff -r 1ecbf90070ad -r ce4f95c56f02 Makefile.am
--- a/Makefile.am Mon Jun 11 10:36:09 2012 -0400
+++ b/Makefile.am Mon Jun 11 20:53:23 2012 +0200
@@ -679,12 +679,11 @@
class_names=`cat $(REPRODUCERS_CLASS_NAMES)` ; \
CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):. \
$(BOOT_DIR)/bin/java $(REPRODUCERS_DPARAMETERS) \
- -Xbootclasspath:$(RUNTIME) CommandLine $$class_names \
- > stdout.log 2> stderr.log ; \
- cat stdout.log ; \
- cat stderr.log >&2
+ -Xbootclasspath:$(RUNTIME) CommandLine $$class_names
+
if WITH_XSLTPROC
- $(XSLTPROC) $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(JNLP_TESTS_ENGINE_DIR)/tests-output.xml > $(TESTS_DIR)/index_reproducers.html
+ $(XSLTPROC) $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/logs.xsl $(JNLP_TESTS_ENGINE_DIR)/ServerAccess-logs.xml > $(TESTS_DIR)/logs_reproducers.html
+ $(XSLTPROC) --stringparam logs logs_reproducers.html $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(JNLP_TESTS_ENGINE_DIR)/tests-output.xml > $(TESTS_DIR)/index_reproducers.html
endif
touch $@
@@ -833,12 +832,10 @@
cd $(NETX_UNIT_TEST_DIR) ; \
class_names=`cat $(UNIT_CLASS_NAMES)` ; \
CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):$(JNLP_TESTS_ENGINE_DIR):. \
- $(BOOT_DIR)/bin/java -Xbootclasspath:$(RUNTIME) CommandLine $$class_names \
- > stdout.log 2> stderr.log ; \
- cat stdout.log ; \
- cat stderr.log >&2
+ $(BOOT_DIR)/bin/java -Xbootclasspath:$(RUNTIME) CommandLine $$class_names
if WITH_XSLTPROC
- $(XSLTPROC) $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(NETX_UNIT_TEST_DIR)/tests-output.xml > $(TESTS_DIR)/index_unit.html
+ $(XSLTPROC) $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/logs.xsl $(NETX_UNIT_TEST_DIR)/ServerAccess-logs.xml > $(TESTS_DIR)/logs_unit.html
+ $(XSLTPROC) --stringparam logs logs_unit.html $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(NETX_UNIT_TEST_DIR)/tests-output.xml > $(TESTS_DIR)/index_unit.html
endif
touch $@
@@ -1016,7 +1013,7 @@
clean_tests_reports:
rm -rf $(TESTS_DIR)/$(REPORT_STYLES_DIRNAME)/
- rm -f $(TESTS_DIR)/index*.html
+ rm -f $(TESTS_DIR)/*.html
clean-netx-dist-tests: clean_tests_reports netx-dist-tests-remove-cert-from-public
rm -f netx-dist-tests-source-files.txt
diff -r 1ecbf90070ad -r ce4f95c56f02 tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java
--- a/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java Mon Jun 11 10:36:09 2012 -0400
+++ b/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java Mon Jun 11 20:53:23 2012 +0200
@@ -225,7 +225,7 @@
try {
pr = server.executeJavawsHeadless(args, jnlp);
} catch (Exception ex) {
- ex.printStackTrace();
+ ServerAccess.logException(ex);
} finally {
finished = true;
}
diff -r 1ecbf90070ad -r ce4f95c56f02 tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java
--- a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java Mon Jun 11 10:36:09 2012 -0400
+++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java Mon Jun 11 20:53:23 2012 +0200
@@ -64,12 +64,12 @@
for (int i = 0; i < simpleContent.length; i++) {
File file = simpleContent[i];
- System.err.print(file.getName());
+ ServerAccess.logOutputReprint(file.getName());
//server port have in fact no usage in converting filename to uri-like-filename.
//But if there is null, instead if some number, then nullpointer exception is thrown (Integer->int).
//So I'm using "real" currently used port, instead of some random value.
URI u = new URI((String)null,(String)null,(String)null,server.getPort(),file.getName(),(String)null,null);
- System.err.println(" ("+u.toString()+")");
+ ServerAccess.logOutputReprint(" ("+u.toString()+")");
String fname=u.toString();
if (file.getName().toLowerCase().endsWith(".jnlp")) {
String c = server.getResourceAsString("/" + fname);
@@ -98,13 +98,13 @@
@Override
public void charReaded(char ch) {
- //System.out.println("OO recieved char: "+ch);
+ //ServerAccess.logOutputReprint("OO recieved char: "+ch);
o1.append(ch);
}
@Override
public void lineReaded(String s) {
- //System.out.println("OO recieved line: "+s);
+ //ServerAccess.logOutputReprint("OO recieved line: "+s);
o2.append(s).append("\n");
}
};
@@ -112,22 +112,22 @@
@Override
public void charReaded(char ch) {
- //System.out.println("EE recieved char: "+ch);
+ //ServerAccess.logOutputReprint("EE recieved char: "+ch);
e1.append(ch);
}
@Override
public void lineReaded(String s) {
- //System.out.println("EE recieved line: "+s);
+ //ServerAccess.logOutputReprint("EE recieved line: "+s);
e2.append(s).append("\n");
}
};
ServerAccess.ProcessResult pr=server.executeBrowser("simpletest1.jnlp",le,lo);
pr.process.destroy();
-// System.out.println("total o");
-// System.out.println(pr.stdout);
-// System.out.println("total e");
-// System.out.println(pr.stderr);
+// ServerAccess.logOutputReprint("total o");
+// ServerAccess.logOutputReprint(pr.stdout);
+// ServerAccess.logOutputReprint("total e");
+// ServerAccess.logOutputReprint(pr.stderr);
Assert.assertEquals(pr.stdout, o1.toString());
Assert.assertEquals(pr.stderr, e1.toString());
//the last \n is mandatory as las tline is flushed also when proces dies
diff -r 1ecbf90070ad -r ce4f95c56f02 tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java
--- a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java Mon Jun 11 10:36:09 2012 -0400
+++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java Mon Jun 11 20:53:23 2012 +0200
@@ -42,12 +42,17 @@
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
import java.io.Reader;
+import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
@@ -57,8 +62,13 @@
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import org.junit.Assert;
@@ -120,8 +130,166 @@
* this flag is indicating whether output of executeProcess should be logged. By default true.
*/
public static boolean PROCESS_LOG = true;
+ public static boolean LOGS_REPRINT = false;
/**
+ * map of classes, each have map of methods, each have errorlist, outLIst, and allList (allist contains also not std or err messages)
+ * class.testMethod.logs
+ */
+ private static final Map<String, Map<String, TestsLogs>> processLogs = new HashMap<String, Map<String, TestsLogs>>(100);
+ private static final File DEFAULT_LOG_FILE = new File("ServerAccess-logs.xml");
+ private static final File DEFAULT_STDERR_FILE = new File("stderr.log");
+ private static final File DEFAULT_STDOUT_FILE = new File("stdout.log");
+ private static final File DEFAULT_STDLOGS_FILE = new File("all.log");
+ private static BufferedWriter DEFAULT_STDERR_WRITER;
+ private static BufferedWriter DEFAULT_STDOUT_WRITER;
+ private static BufferedWriter DEFAULT_STDLOGS_WRITER;
+
+ static{
+ try{
+ DEFAULT_STDOUT_WRITER=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(DEFAULT_STDOUT_FILE)));
+ DEFAULT_STDERR_WRITER=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(DEFAULT_STDERR_FILE)));
+ DEFAULT_STDLOGS_WRITER=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(DEFAULT_STDLOGS_FILE)));
+ }catch(Throwable t){
+ t.printStackTrace();
+ }
+ }
+ private static final String LOGS_ELEMENT = "logs";
+ private static final String CLASSLOG_ELEMENT = "classlog";
+ private static final String CLASSNAME_ATTRIBUTE = "className";
+ private static final String TESTLOG_ELEMENT = "testLog";
+ private static final String TESTMETHOD_ATTRIBUTE = "testMethod";
+ private static final String FULLID_ATTRIBUTE = "fullId";
+ private static final String LOG_ELEMENT = "log";
+ private static final String LOG_ID_ATTRIBUTE = "id";
+ private static final String ITEM_ELEMENT = "item";
+ private static final String ITEM_ID_ATTRIBUTE = "id";
+ private static final String STAMP_ELEMENT = "stamp";
+ private static final String TEXT_ELEMENT = "text";
+ private static final String FULLTRACE_ELEMENT = "fulltrace";
+
+ private static void writeXmlLog() throws FileNotFoundException, IOException {
+ writeXmlLog(DEFAULT_LOG_FILE);
+ }
+
+ private static void writeXmlLog(File f) throws FileNotFoundException, IOException {
+ Writer w = new OutputStreamWriter(new FileOutputStream(f));
+ Set<Entry<String, Map<String, TestsLogs>>> classes = processLogs.entrySet();
+ w.write("<" + LOGS_ELEMENT + ">");
+ for (Entry<String, Map<String, TestsLogs>> classLog : classes) {
+ String className = classLog.getKey();
+ w.write("<" + CLASSLOG_ELEMENT + " " + CLASSNAME_ATTRIBUTE + "=\"" + className + "\">");
+ Set<Entry<String, TestsLogs>> testsLogs = classLog.getValue().entrySet();
+ for (Entry<String, TestsLogs> testLog : testsLogs) {
+ String testName = testLog.getKey();
+ String testLogs = testLog.getValue().toString();
+ w.write("<" + TESTLOG_ELEMENT + " " + TESTMETHOD_ATTRIBUTE + "=\"" + testName + "\" " + FULLID_ATTRIBUTE + "=\"" + className + "." + testName + "\" >");
+ w.write(testLogs);
+ w.write("</" + TESTLOG_ELEMENT + ">");
+ }
+ w.write("</" + CLASSLOG_ELEMENT + ">");
+ }
+ w.write("</" + LOGS_ELEMENT + ">");
+ w.flush();
+ w.close();
+ }
+
+ private static void addToXmlLog(String message, boolean printToOut, boolean printToErr, StackTraceElement ste) {
+ Map<String, TestsLogs> classLog = processLogs.get(ste.getClassName());
+ if (classLog == null) {
+ classLog = new HashMap<String, TestsLogs>(50);
+ processLogs.put(ste.getClassName(), classLog);
+ }
+ TestsLogs methodLog = classLog.get(ste.getMethodName());
+ if (methodLog == null) {
+ methodLog = new TestsLogs();
+ classLog.put(ste.getMethodName(), methodLog);
+ }
+ methodLog.add(printToErr, printToOut, message);
+ }
+
+ private static class TestsLogs {
+
+ public final List<LogItem> outs = new LinkedList<LogItem>();
+ public final List<LogItem> errs = new LinkedList<LogItem>();
+ public final List<LogItem> all = new LinkedList<LogItem>();
+ private static boolean added = false;
+
+ public synchronized void add(boolean err, boolean out, String text) {
+ if (text == null) {
+ text = "null";
+ }
+ LogItem li = new LogItem(text);
+ if (out) {
+ outs.add(li);
+ }
+ if (err) {
+ errs.add(li);
+ }
+ all.add(li);
+ if (!added) {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+
+ @Override
+ public void run() {
+ try {
+ writeXmlLog();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ added = true;
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = listToStringBuilder(outs, "out");
+ sb.append(listToStringBuilder(errs, "err"));
+ sb.append(listToStringBuilder(all, "all"));
+ return sb.toString();
+ }
+
+ private StringBuilder listToStringBuilder(List<LogItem> l, String id) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<" + LOG_ELEMENT + " " + LOG_ID_ATTRIBUTE + "=\"").append(id).append("\">\n");
+ int i = 0;
+ for (LogItem logItem : l) {
+ i++;
+ sb.append(logItem.toStringBuilder(i));
+ }
+ sb.append("</" + LOG_ELEMENT + ">\n");
+ return sb;
+ }
+ };
+
+ private static class LogItem {
+
+ public final Date timeStamp = new Date();
+ public final StackTraceElement[] fullTrace = Thread.currentThread().getStackTrace();
+ public final String text;
+
+ public LogItem(String text) {
+ this.text = text;
+ }
+
+ public StringBuilder toStringBuilder(int id) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" <" + ITEM_ELEMENT + " " + ITEM_ID_ATTRIBUTE + "=\"").append(id).append("\">\n");
+ sb.append(" <" + STAMP_ELEMENT + "><![CDATA[").append(timeStamp.toString()).append("]]></" + STAMP_ELEMENT + ">\n");
+ sb.append(" <" + TEXT_ELEMENT + "><![CDATA[\n").append(text).append("\n]]></" + TEXT_ELEMENT + ">\n");
+ sb.append(" <" + FULLTRACE_ELEMENT + "><![CDATA[\n");
+ //five methods since call in log methods + getStacktrace method
+ for (int i = 6; i < fullTrace.length; i++) {
+ sb.append(fullTrace[i].toString()).append("\n");
+ }
+ sb.append("\n]]> </" + FULLTRACE_ELEMENT + ">\n");
+ sb.append(" </" + ITEM_ELEMENT + ">\n");
+ return sb;
+ }
+ }
+ /**
* main method of this class prints out random free port
* or runs server
* param "port" prints out the port
@@ -562,7 +730,10 @@
* @throws IOException
*/
public static void saveFile(String content, File f) throws IOException {
- Writer output = new BufferedWriter(new FileWriter(f));
+ saveFile(content, f, "utf-8");
+ }
+ public static void saveFile(String content, File f,String encoding) throws IOException {
+ Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f),encoding));
output.write(content);
output.flush();
output.close();
@@ -762,11 +933,45 @@
idded = fullId + ": " + message;
}
+ if (LOGS_REPRINT) {
+ if (printToOut) {
+ System.out.println(idded);
+ }
+ if (printToErr) {
+ System.err.println(idded);
+ }
+ }
+ try{
if (printToOut) {
- System.out.println(idded);
+ DEFAULT_STDOUT_WRITER.write(idded);
+ DEFAULT_STDOUT_WRITER.newLine();
}
if (printToErr) {
- System.err.println(idded);
+ DEFAULT_STDERR_WRITER.write(idded);
+ DEFAULT_STDERR_WRITER.newLine();
+ }
+ DEFAULT_STDLOGS_WRITER.write(idded);
+ DEFAULT_STDLOGS_WRITER.newLine();
+ }catch (Throwable t){
+ t.printStackTrace();
+ }
+
+ addToXmlLog(message,printToOut,printToErr,ste);
+ }
+
+ public static void logException(Throwable t){
+ logException(t, true);
+ }
+ public static void logException(Throwable t, boolean print){
+ try{
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ log(sw.toString(), false, print);
+ pw.close();
+ sw.close();
+ }catch(Exception ex){
+ throw new RuntimeException(ex);
}
}
@@ -789,6 +994,12 @@
break;
}
}
+ //if nothing left in stack then we have been in ServerAccess already
+ //so the target method is the highest form it and better to return it
+ //rather then die to ArrayOutOfBounds
+ if(i >= stack.length){
+ return result;
+ }
//now we are out of net.sourceforge.jnlp.ServerAccess
//method we need (the test) is highest from following class
baseClass = stack[i].getClassName();
@@ -1073,9 +1284,9 @@
String op = t.nextToken();
String p = op;
if (p.startsWith(XSX))p=p.replace(XSX, "/");
- System.err.println("Getting: "+p);
+ logNoReprint("Getting: "+p);
p=URLDecoder.decode(p, "UTF-8");
- System.err.println("Serving: "+p);
+ logNoReprint("Serving: "+p);
p = (".".concat(((p.endsWith("/")) ? p.concat(
"index.html") : p))).replace('/', File.separatorChar);
File pp = new File(dir, p);
@@ -1107,14 +1318,14 @@
}
}
}catch (SocketException e) {
- e.printStackTrace();
+ logException(e, false);
} catch (Exception e) {
o.writeBytes("HTTP/1.0 404 ERROR\n\n\n");
- e.printStackTrace();
+ logException(e, false);
}
o.close();
} catch (Exception e) {
- e.printStackTrace();
+ logException(e, false);
}
}
}
@@ -1248,14 +1459,13 @@
this.canRun = canRun;
if (p != null) {
if (p.getP() != null) {
- System.err.println("Stopping assassin for" + p.toString() + " " + p.getP().toString() + " " + p.getCommandLine() + ": ");
+ logNoReprint("Stopping assassin for" + p.toString() + " " + p.getP().toString() + " " + p.getCommandLine() + ": ");
} else {
- System.err.println("Stopping assassin for" + p.toString() + " " + p.getCommandLine() + ": ");
+ logNoReprint("Stopping assassin for" + p.toString() + " " + p.getCommandLine() + ": ");
}
} else {
- System.err.println("Stopping assassin for null job: ");
+ logNoReprint("Stopping assassin for null job: ");
}
- System.err.flush();
}
public boolean isCanRun() {
@@ -1288,11 +1498,10 @@
try {
if (p != null) {
if (p.getP() != null) {
- System.err.println("Timed out " + p.toString() + " " + p.getP().toString() + " .. killing " + p.getCommandLine() + ": ");
+ logErrorReprint("Timed out " + p.toString() + " " + p.getP().toString() + " .. killing " + p.getCommandLine() + ": ");
} else {
- System.err.println("Timed out " + p.toString() + " " + "null .. killing " + p.getCommandLine() + ": ");
+ logErrorReprint("Timed out " + p.toString() + " " + "null .. killing " + p.getCommandLine() + ": ");
}
- System.err.flush();
wasTerminated = true;
p.interrupt();
while (!terminated.contains(p)) {
@@ -1311,13 +1520,12 @@
More information about the distro-pkg-dev
mailing list