Skip to content

Commit 8281b07

Browse files
committed
Mods to use shared Logger from GitLabApi class (#228).
1 parent 4eb856c commit 8281b07

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/main/java/org/gitlab4j/api/systemhooks/SystemHookManager.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import javax.servlet.http.HttpServletRequest;
1111

12+
import org.gitlab4j.api.GitLabApi;
1213
import org.gitlab4j.api.GitLabApiException;
1314
import org.gitlab4j.api.HookManager;
1415
import org.gitlab4j.api.utils.HttpRequestUtils;
@@ -21,7 +22,7 @@ public class SystemHookManager extends HookManager {
2122

2223
public static final String SYSTEM_HOOK_EVENT = "System Hook";
2324

24-
private final static Logger LOG = Logger.getLogger(SystemHookManager.class.getName());
25+
private final static Logger LOGGER = GitLabApi.getLogger();
2526
private final JacksonJson jacksonJson = new JacksonJson();
2627

2728
// Collection of objects listening for System Hook events.
@@ -55,27 +56,27 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
5556

5657
if (!isValidSecretToken(request)) {
5758
String message = "X-Gitlab-Token mismatch!";
58-
LOG.warning(message);
59+
LOGGER.warning(message);
5960
throw new GitLabApiException(message);
6061
}
6162

6263
String eventName = request.getHeader("X-Gitlab-Event");
63-
LOG.info("handleEvent: X-Gitlab-Event=" + eventName);
64+
LOGGER.info("handleEvent: X-Gitlab-Event=" + eventName);
6465
if (!SYSTEM_HOOK_EVENT.equals(eventName)) {
6566
String message = "Unsupported X-Gitlab-Event, event Name=" + eventName;
66-
LOG.warning(message);
67+
LOGGER.warning(message);
6768
throw new GitLabApiException(message);
6869
}
6970

7071
try {
7172

7273
SystemHookEvent event;
73-
if (LOG.isLoggable(Level.FINE)) {
74-
LOG.fine(HttpRequestUtils.getShortRequestDump("System Hook", true, request));
74+
if (LOGGER.isLoggable(Level.FINE)) {
75+
LOGGER.fine(HttpRequestUtils.getShortRequestDump("System Hook", true, request));
7576
String postData = HttpRequestUtils.getPostDataAsString(request);
76-
LOG.fine("Raw POST data:\n" + postData);
77+
LOGGER.fine("Raw POST data:\n" + postData);
7778
event = jacksonJson.unmarshal(SystemHookEvent.class, postData);
78-
LOG.fine(event.getEventName() + "\n" + jacksonJson.marshal(event) + "\n");
79+
LOGGER.fine(event.getEventName() + "\n" + jacksonJson.marshal(event) + "\n");
7980
} else {
8081
InputStreamReader reader = new InputStreamReader(request.getInputStream());
8182
event = jacksonJson.unmarshal(SystemHookEvent.class, reader);
@@ -84,7 +85,7 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
8485
fireEvent(event);
8586

8687
} catch (Exception e) {
87-
LOG.warning("Error processing JSON data, exception=" +
88+
LOGGER.warning("Error processing JSON data, exception=" +
8889
e.getClass().getSimpleName() + ", error=" + e.getMessage());
8990
throw new GitLabApiException(e);
9091
}
@@ -98,10 +99,10 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
9899
*/
99100
public void handleEvent(SystemHookEvent event) throws GitLabApiException {
100101
if (event != null) {
101-
LOG.info("handleEvent:" + event.getClass().getSimpleName() + ", eventName=" + event.getEventName());
102+
LOGGER.info("handleEvent:" + event.getClass().getSimpleName() + ", eventName=" + event.getEventName());
102103
fireEvent(event);
103104
} else {
104-
LOG.warning("handleEvent: provided event cannot be null!");
105+
LOGGER.warning("handleEvent: provided event cannot be null!");
105106
}
106107
}
107108

@@ -154,7 +155,7 @@ public void fireEvent(SystemHookEvent event) throws GitLabApiException {
154155
fireRepositoryEvent((RepositorySystemHookEvent) event);
155156
} else {
156157
String message = "Unsupported event, event_named=" + event.getEventName();
157-
LOG.warning(message);
158+
LOGGER.warning(message);
158159
throw new GitLabApiException(message);
159160
}
160161
}

src/main/java/org/gitlab4j/api/webhook/WebHookManager.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import javax.servlet.http.HttpServletRequest;
1111

12+
import org.gitlab4j.api.GitLabApi;
1213
import org.gitlab4j.api.GitLabApiException;
1314
import org.gitlab4j.api.HookManager;
1415
import org.gitlab4j.api.utils.HttpRequestUtils;
@@ -19,7 +20,7 @@
1920
*/
2021
public class WebHookManager extends HookManager {
2122

22-
private final static Logger LOG = Logger.getLogger(WebHookManager.class.getName());
23+
private final static Logger LOGGER = GitLabApi.getLogger();
2324
private final JacksonJson jacksonJson = new JacksonJson();
2425

2526
// Collection of objects listening for WebHook events.
@@ -53,12 +54,12 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
5354

5455
if (!isValidSecretToken(request)) {
5556
String message = "X-Gitlab-Token mismatch!";
56-
LOG.warning(message);
57+
LOGGER.warning(message);
5758
throw new GitLabApiException(message);
5859
}
5960

6061
String eventName = request.getHeader("X-Gitlab-Event");
61-
LOG.info("handleEvent: X-Gitlab-Event=" + eventName);
62+
LOGGER.info("handleEvent: X-Gitlab-Event=" + eventName);
6263
switch (eventName) {
6364

6465
case BuildEvent.BUILD_HOOK_X_GITLAB_EVENT:
@@ -74,19 +75,19 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
7475

7576
default:
7677
String message = "Unsupported X-Gitlab-Event, event Name=" + eventName;
77-
LOG.warning(message);
78+
LOGGER.warning(message);
7879
throw new GitLabApiException(message);
7980
}
8081

8182
try {
8283

8384
Event event;
84-
if (LOG.isLoggable(Level.FINE)) {
85-
LOG.fine(HttpRequestUtils.getShortRequestDump(eventName + " webhook", true, request));
85+
if (LOGGER.isLoggable(Level.FINE)) {
86+
LOGGER.fine(HttpRequestUtils.getShortRequestDump(eventName + " webhook", true, request));
8687
String postData = HttpRequestUtils.getPostDataAsString(request);
87-
LOG.fine("Raw POST data:\n" + postData);
88+
LOGGER.fine("Raw POST data:\n" + postData);
8889
event = jacksonJson.unmarshal(Event.class, postData);
89-
LOG.fine(event.getObjectKind() + " event:\n" + jacksonJson.marshal(event) + "\n");
90+
LOGGER.fine(event.getObjectKind() + " event:\n" + jacksonJson.marshal(event) + "\n");
9091
} else {
9192
InputStreamReader reader = new InputStreamReader(request.getInputStream());
9293
event = jacksonJson.unmarshal(Event.class, reader);
@@ -95,7 +96,7 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
9596
fireEvent(event);
9697

9798
} catch (Exception e) {
98-
LOG.warning("Error parsing JSON data, exception=" + e.getClass().getSimpleName() + ", error=" + e.getMessage());
99+
LOGGER.warning("Error parsing JSON data, exception=" + e.getClass().getSimpleName() + ", error=" + e.getMessage());
99100
throw new GitLabApiException(e);
100101
}
101102
}
@@ -108,7 +109,7 @@ public void handleEvent(HttpServletRequest request) throws GitLabApiException {
108109
*/
109110
public void handleEvent(Event event) throws GitLabApiException {
110111

111-
LOG.info("handleEvent: object_kind=" + event.getObjectKind());
112+
LOGGER.info("handleEvent: object_kind=" + event.getObjectKind());
112113

113114
switch (event.getObjectKind()) {
114115
case BuildEvent.OBJECT_KIND:
@@ -123,7 +124,7 @@ public void handleEvent(Event event) throws GitLabApiException {
123124

124125
default:
125126
String message = "Unsupported event object_kind, object_kind=" + event.getObjectKind();
126-
LOG.warning(message);
127+
LOGGER.warning(message);
127128
throw new GitLabApiException(message);
128129
}
129130

@@ -194,7 +195,7 @@ public void fireEvent(Event event) throws GitLabApiException {
194195

195196
default:
196197
String message = "Unsupported event object_kind, object_kind=" + event.getObjectKind();
197-
LOG.warning(message);
198+
LOGGER.warning(message);
198199
throw new GitLabApiException(message);
199200
}
200201
}

0 commit comments

Comments
 (0)