Skip to content

Commit

Permalink
New: custom logging in violations-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jul 5, 2020
1 parent ea59576 commit 1bd2db1
Showing 1 changed file with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
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;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.remoting.VirtualChannel;
import hudson.util.Secret;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Violation> allParsedViolations = new TreeSet<>();
for (final ViolationConfig violationConfig : config.getViolationConfigs()) {
Expand Down

0 comments on commit 1bd2db1

Please sign in to comment.