Skip to content

Commit

Permalink
Merge pull request #129 from jglick/SupportLogFormatter-HOSTING-742
Browse files Browse the repository at this point in the history
[HOSTING-742] Using external lib-support-log-formatter
  • Loading branch information
jglick authored Apr 12, 2019
2 parents e669709 + 730bd04 commit 2281a68
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 214 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ THE SOFTWARE.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins.lib</groupId>
<artifactId>support-log-formatter</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.netbeans.modules</groupId>
<artifactId>org-netbeans-insane</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jvnet/hudson/test/BuildWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/jvnet/hudson/test/DeltaSupportLogFormatter.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -1018,7 +1018,7 @@ private static final class RemoteLogDumper extends MasterToSlaveCallable<Void, R
}
@Override public Void call() throws RuntimeException {
Handler handler = new Handler() {
final Formatter formatter = new SupportLogFormatter();
final Formatter formatter = new DeltaSupportLogFormatter();
@Override public void publish(LogRecord record) {
if (isLoggable(record)) {
stderr.getLogger().print(formatter.format(record).replaceAll("(?m)^", "[" + name + "] "));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jvnet/hudson/test/LoggerRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class LoggerRule extends ExternalResource {
* Initializes the rule, by default not recording anything.
*/
public LoggerRule() {
consoleHandler.setFormatter(new SupportLogFormatter());
consoleHandler.setFormatter(new DeltaSupportLogFormatter());
consoleHandler.setLevel(Level.ALL);
}

Expand Down
210 changes: 0 additions & 210 deletions src/main/java/org/jvnet/hudson/test/SupportLogFormatter.java

This file was deleted.

0 comments on commit 2281a68

Please sign in to comment.