Skip to content

Commit fe98dad

Browse files
committed
Exception logging in build job log
1 parent 28d8849 commit fe98dad

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apply from: project.buildscript.classLoader.getResource('release.gradle').toURI(
1919

2020

2121
dependencies {
22-
compile 'se.bjurr.violations:violation-comments-lib:1.69'
22+
compile 'se.bjurr.violations:violation-comments-lib:1.70'
2323
compile 'com.jayway.jsonpath:json-path:2.0.0'
2424
compile 'com.google.code.gson:gson:2.8.0'
2525
compile 'com.google.guava:guava:20.0'

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/BitbucketServerCommentsProvider.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import static com.google.common.base.Suppliers.memoizeWithExpiration;
55
import static com.google.common.collect.Lists.newArrayList;
66
import static java.util.concurrent.TimeUnit.SECONDS;
7+
import static java.util.logging.Level.SEVERE;
78
import static se.bjurr.violations.comments.bitbucketserver.lib.client.model.DIFFTYPE.ADDED;
89

910
import com.google.common.annotations.VisibleForTesting;
1011
import com.google.common.base.Supplier;
1112
import java.util.ArrayList;
1213
import java.util.List;
13-
import org.slf4j.Logger;
14-
import org.slf4j.LoggerFactory;
1514
import se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient;
1615
import se.bjurr.violations.comments.bitbucketserver.lib.client.model.BitbucketServerComment;
1716
import se.bjurr.violations.comments.bitbucketserver.lib.client.model.BitbucketServerDiff;
@@ -28,8 +27,6 @@
2827

2928
public class BitbucketServerCommentsProvider implements CommentsProvider {
3029

31-
private static final Logger LOG = LoggerFactory.getLogger(BitbucketServerCommentsProvider.class);
32-
3330
private final BitbucketServerClient client;
3431

3532
private final Supplier<BitbucketServerDiffResponse> diffResponse =
@@ -44,16 +41,19 @@ public BitbucketServerDiffResponse get() {
4441
SECONDS);
4542

4643
private final ViolationCommentsToBitbucketServerApi violationCommentsToBitbucketApi;
44+
private final ViolationsLogger violationsLogger;
4745

4846
@VisibleForTesting
4947
BitbucketServerCommentsProvider() {
5048
client = null;
5149
violationCommentsToBitbucketApi = null;
50+
violationsLogger = null;
5251
}
5352

5453
public BitbucketServerCommentsProvider(
5554
final ViolationCommentsToBitbucketServerApi violationCommentsToBitbucketApi,
5655
final ViolationsLogger violationsLogger) {
56+
this.violationsLogger = violationsLogger;
5757
final String bitbucketServerBaseUrl = violationCommentsToBitbucketApi.getBitbucketServerUrl();
5858
final String bitbucketServerProject = violationCommentsToBitbucketApi.getProjectKey();
5959
final String bitbucketServerRepo = violationCommentsToBitbucketApi.getRepoSlug();
@@ -137,7 +137,8 @@ public void removeComments(final List<Comment> comments) {
137137
commentVersion = Integer.valueOf(comment.getSpecifics().get(0));
138138
client.pullRequestRemoveComment(commentId, commentVersion);
139139
} catch (final Exception e) {
140-
LOG.warn("Was unable to remove comment " + commentId + " " + commentVersion, e);
140+
violationsLogger.log(
141+
SEVERE, "Was unable to remove comment " + commentId + " " + commentVersion, e);
141142
}
142143
}
143144
}

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/ViolationCommentsToBitbucketServerApi.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty;
88

99
import java.util.List;
10-
import org.slf4j.LoggerFactory;
10+
import java.util.logging.Level;
11+
import java.util.logging.Logger;
1112
import se.bjurr.violations.comments.lib.CommentsProvider;
1213
import se.bjurr.violations.comments.lib.ViolationsLogger;
1314
import se.bjurr.violations.lib.model.Violation;
@@ -48,8 +49,13 @@ public static ViolationCommentsToBitbucketServerApi violationCommentsToBitbucket
4849
private ViolationsLogger violationsLogger =
4950
new ViolationsLogger() {
5051
@Override
51-
public void log(final String string) {
52-
LoggerFactory.getLogger(ViolationsLogger.class).info(string);
52+
public void log(final Level level, final String string) {
53+
Logger.getLogger(ViolationsLogger.class.getSimpleName()).log(level, string);
54+
}
55+
56+
@Override
57+
public void log(final Level level, final String string, final Throwable t) {
58+
Logger.getLogger(ViolationsLogger.class.getSimpleName()).log(level, string, t);
5359
}
5460
};
5561

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/client/BitbucketServerClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.google.common.base.Charsets.UTF_8;
44
import static com.google.common.collect.Lists.newArrayList;
55
import static java.net.URLEncoder.encode;
6+
import static java.util.logging.Level.INFO;
67
import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty;
78

89
import com.google.common.annotations.VisibleForTesting;
@@ -102,6 +103,7 @@ public List<String> pullRequestChanges() {
102103
List<String> response = JsonPath.read(json, jsonPath);
103104
if (response.isEmpty()) {
104105
violationsLogger.log(
106+
INFO,
105107
"Found no changed files from "
106108
+ url
107109
+ " with JSONPath "
@@ -179,12 +181,13 @@ public List<BitbucketServerComment> pullRequestComments(final String changedFile
179181

180182
if (parsed.isEmpty()) {
181183
violationsLogger.log(
184+
INFO,
182185
"Found no comments from " + url + " with JSONPath " + jsonPath + " in JSON:\n" + json);
183186
}
184187

185188
return toBitbucketServerComments(parsed);
186189
} catch (final UnsupportedEncodingException e) {
187-
throw new RuntimeException(e);
190+
throw new RuntimeException(e.getMessage(), e);
188191
}
189192
}
190193

@@ -195,7 +198,7 @@ public BitbucketServerDiffResponse pullRequestDiff() {
195198
final BitbucketServerDiffResponse diff =
196199
new Gson().fromJson(json, BitbucketServerDiffResponse.class);
197200
if (diff.getDiffs().isEmpty()) {
198-
violationsLogger.log("Found no diffs from " + url + " in JSON:\n" + json);
201+
violationsLogger.log(INFO, "Found no diffs from " + url + " in JSON:\n" + json);
199202
}
200203
return diff;
201204
} catch (final Exception e) {

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/client/BitbucketServerInvoker.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static com.google.common.base.Charsets.UTF_8;
44
import static com.google.common.base.Strings.isNullOrEmpty;
55

6-
import com.google.common.base.Throwables;
76
import java.io.BufferedReader;
87
import java.io.IOException;
98
import java.io.InputStreamReader;
@@ -129,7 +128,7 @@ private String doInvokeUrl(
129128
}
130129

131130
} catch (final IOException e) {
132-
throw Throwables.propagate(e);
131+
throw new RuntimeException(e.getMessage(), e);
133132
}
134133
}
135134
}

src/test/java/se/bjurr/violations/comments/bitbucketserver/lib/client/BitbucketServerClientTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.google.common.io.Resources;
1111
import java.io.IOException;
1212
import java.util.List;
13+
import java.util.logging.Level;
1314
import java.util.logging.Logger;
1415
import org.junit.Before;
1516
import org.junit.Test;
@@ -27,9 +28,15 @@ public class BitbucketServerClientTest {
2728
new BitbucketServerClient(
2829
new ViolationsLogger() {
2930
@Override
30-
public void log(final String string) {
31+
public void log(final Level level, final String string) {
3132
Logger.getLogger(BitbucketServerClientTest.class.getSimpleName()).info(string);
3233
}
34+
35+
@Override
36+
public void log(final Level level, final String string, final Throwable t) {
37+
Logger.getLogger(BitbucketServerClientTest.class.getSimpleName())
38+
.log(Level.SEVERE, string, t);
39+
}
3340
},
3441
"bitbucketServerBaseUrl",
3542
"bitbucketServerProject",

0 commit comments

Comments
 (0)