diff --git a/pom.xml b/pom.xml
index 48e4b4a0a..13ebf7380 100644
--- a/pom.xml
+++ b/pom.xml
@@ -139,6 +139,11 @@ THE SOFTWARE.
+
+ io.jenkins.lib
+ support-log-formatter
+ 1.0
+
org.netbeans.modules
org-netbeans-insane
diff --git a/src/main/java/org/jvnet/hudson/test/BuildWatcher.java b/src/main/java/org/jvnet/hudson/test/BuildWatcher.java
index b877326f6..a277df981 100644
--- a/src/main/java/org/jvnet/hudson/test/BuildWatcher.java
+++ b/src/main/java/org/jvnet/hudson/test/BuildWatcher.java
@@ -153,7 +153,7 @@ private static final class LogLinePrefixOutputFilter extends LineTransformationO
}
@Override protected void eol(byte[] b, int len) throws IOException {
- logger.append(SupportLogFormatter.elapsedTime());
+ logger.append(DeltaSupportLogFormatter.elapsedTime());
logger.write(' ');
logger.append(prefix);
logger.write(b, 0, len);
diff --git a/src/main/java/org/jvnet/hudson/test/DeltaSupportLogFormatter.java b/src/main/java/org/jvnet/hudson/test/DeltaSupportLogFormatter.java
new file mode 100644
index 000000000..318187642
--- /dev/null
+++ b/src/main/java/org/jvnet/hudson/test/DeltaSupportLogFormatter.java
@@ -0,0 +1,45 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2013, CloudBees, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.jvnet.hudson.test;
+
+import io.jenkins.lib.support_log_formatter.SupportLogFormatter;
+import java.util.logging.LogRecord;
+
+class DeltaSupportLogFormatter extends SupportLogFormatter {
+
+ private static long start = System.nanoTime();
+ static String elapsedTime() {
+ return String.format("%8.3f", (System.nanoTime() - start) / 1_000_000_000.0);
+ }
+
+ DeltaSupportLogFormatter() {
+ start = System.nanoTime(); // reset for each test, if using LoggerRule
+ }
+
+ @Override protected String formatTime(LogRecord record) {
+ return elapsedTime();
+ }
+
+}
diff --git a/src/main/java/org/jvnet/hudson/test/JenkinsRule.java b/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
index edb01cf15..193eeca52 100644
--- a/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
+++ b/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
@@ -349,7 +349,7 @@ public Jenkins getInstance() {
public void before() throws Throwable {
for (Handler h : Logger.getLogger("").getHandlers()) {
if (h instanceof ConsoleHandler) {
- ((ConsoleHandler) h).setFormatter(new SupportLogFormatter());
+ ((ConsoleHandler) h).setFormatter(new DeltaSupportLogFormatter());
}
}
@@ -1018,7 +1018,7 @@ private static final class RemoteLogDumper extends MasterToSlaveCallable 0 ? indexes[i - 1] : -1;
- int available = indexes[i] - previous - 1;
- int length = requiredSavings > 0 ? (available < 1) ? available : 1 : available;
- requiredSavings -= (available - length);
- lengths[i] = length + 1;
- }
- lengths[count] = fqcnLength - indexes[count - 1];
- for (int i = 0; i <= count; i++) {
- if (i == 0) {
- buf.append(fqcn.substring(0, lengths[i] - 1));
- } else {
- buf.append(fqcn.substring(indexes[i - 1], indexes[i - 1] + lengths[i]));
- }
- }
- return buf.toString();
- }
-
- // Copied from hudson.Functions, but with external references removed:
- public static String printThrowable(Throwable t) {
- if (t == null) {
- return "No Exception details";
- }
- StringBuilder s = new StringBuilder();
- doPrintStackTrace(s, t, null, "", new HashSet());
- return s.toString();
- }
- private static void doPrintStackTrace(StringBuilder s, Throwable t, Throwable higher, String prefix, Set encountered) {
- if (!encountered.add(t)) {
- s.append("\n");
- return;
- }
- try {
- if (!t.getClass().getMethod("printStackTrace", PrintWriter.class).equals(Throwable.class.getMethod("printStackTrace", PrintWriter.class))) {
- StringWriter sw = new StringWriter();
- t.printStackTrace(new PrintWriter(sw));
- s.append(sw.toString());
- return;
- }
- } catch (NoSuchMethodException x) {
- x.printStackTrace(); // err on the conservative side here
- }
- Throwable lower = t.getCause();
- if (lower != null) {
- doPrintStackTrace(s, lower, t, prefix, encountered);
- }
- for (Throwable suppressed : t.getSuppressed()) {
- s.append(prefix).append("Also: ");
- doPrintStackTrace(s, suppressed, t, prefix + "\t", encountered);
- }
- if (lower != null) {
- s.append(prefix).append("Caused: ");
- }
- String summary = t.toString();
- if (lower != null) {
- String suffix = ": " + lower;
- if (summary.endsWith(suffix)) {
- summary = summary.substring(0, summary.length() - suffix.length());
- }
- }
- s.append(summary).append(LINE_SEPARATOR);
- StackTraceElement[] trace = t.getStackTrace();
- int end = trace.length;
- if (higher != null) {
- StackTraceElement[] higherTrace = higher.getStackTrace();
- while (end > 0) {
- int higherEnd = end + higherTrace.length - trace.length;
- if (higherEnd <= 0 || !higherTrace[higherEnd - 1].equals(trace[end - 1])) {
- break;
- }
- end--;
- }
- }
- for (int i = 0; i < end; i++) {
- s.append(prefix).append("\tat ").append(trace[i]).append(LINE_SEPARATOR);
- }
- }
- private static final String LINE_SEPARATOR = System.getProperty("line.separator");
- public static void printStackTrace(Throwable t, PrintWriter pw) {
- pw.println(printThrowable(t).trim());
- }
- public static void printStackTrace(Throwable t, PrintStream ps) {
- ps.println(printThrowable(t).trim());
- }
-
-}