From 1bd2db1df2165e06878d14940a455e281edb03ee Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Sun, 5 Jul 2020 16:19:26 +0200 Subject: [PATCH] New: custom logging in violations-lib --- .../plugins/jvctb/perform/JvctbPerformer.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java b/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java index f821214..349c631 100644 --- a/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java +++ b/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java @@ -26,6 +26,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.io.CharStreams; + import hudson.EnvVars; import hudson.FilePath; import hudson.FilePath.FileCallable; @@ -33,6 +34,7 @@ import hudson.model.TaskListener; import hudson.remoting.VirtualChannel; import hudson.util.Secret; + import java.io.File; import java.io.IOException; import java.io.InputStreamReader; @@ -44,11 +46,14 @@ import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; + import org.jenkinsci.plugins.jvctb.ProxyConfigDetails; import org.jenkinsci.plugins.jvctb.config.ViolationConfig; import org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfig; +import org.jenkinsci.plugins.jvctg.perform.JvctgPerformer; import org.jenkinsci.plugins.plaincredentials.StringCredentials; import org.jenkinsci.remoting.RoleChecker; + import se.bjurr.violations.comments.bitbucketserver.lib.ViolationCommentsToBitbucketServerApi; import se.bjurr.violations.lib.FilteringViolationsLogger; import se.bjurr.violations.lib.ViolationsLogger; @@ -76,21 +81,26 @@ public static void doPerform( } final Integer pullRequestIdInt = Integer.valueOf(config.getPullRequestId()); - final ViolationsLogger violationsLogger = - FilteringViolationsLogger.filterLevel( - new ViolationsLogger() { - @Override - public void log(final Level level, final String string) { - listener.getLogger().println(level + " " + string); - } + final ViolationsLogger violationsLogger = new ViolationsLogger() { + @Override + public void log(final Level level, final String string, + final Throwable e) { + Logger.getLogger(JvctbPerformer.class.getName()).log(level, + string, e); + final StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + listener.getLogger().println(string + "\n" + sw.toString()); + } - @Override - public void log(final Level level, final String string, final Throwable t) { - final StringWriter sw = new StringWriter(); - t.printStackTrace(new PrintWriter(sw)); - listener.getLogger().println(level + " " + string + "\n" + sw.toString()); - } - }); + @Override + public void log(final Level level, final String string) { + Logger.getLogger(JvctbPerformer.class.getName()).log(level, + string); + if (level != Level.FINE) { + listener.getLogger().println(string); + } + } + }; final Set allParsedViolations = new TreeSet<>(); for (final ViolationConfig violationConfig : config.getViolationConfigs()) {