Skip to content

Commit 9920b66

Browse files
Moved log.error etc. log messages into their respective runOn... methods, replaced with debug logging and if no callback registered then a debug message noting no callback was registered. Set default logging to disable Jetty logs, since they're super spammy--but I did set logs to default for OBS classes so that clients can see error messages etc. and hopefully get the idea they need to register callbacks and can always turn off those logs by setting it to info or whatever. Closes #2
1 parent 21670d3 commit 9920b66

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

src/main/java/net/twasi/obsremotejava/OBSCommunicator.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public void await() throws InterruptedException {
148148

149149
@OnWebSocketError
150150
public void onError(Session session, Throwable throwable) {
151-
151+
// do nothing for now, this should at least repress "OnWebsocketError not registered" messages
152+
runOnError("Websocket error occurred with session " + session, throwable);
152153
}
153154

154155
@OnWebSocketClose
@@ -158,7 +159,7 @@ public void onClose(int statusCode, String reason) {
158159
try {
159160
this.onDisconnect.run(null);
160161
} catch (Throwable t) {
161-
t.printStackTrace();
162+
runOnError("Could not close websocket connection", t);
162163
}
163164
}
164165

@@ -170,7 +171,7 @@ public void onConnect(Session session) {
170171
fut = session.getRemote().sendStringByFuture(new Gson().toJson(new GetVersionRequest(this)));
171172
fut.get(2, TimeUnit.SECONDS);
172173
} catch (Throwable t) {
173-
t.printStackTrace();
174+
runOnError("An error occurred while trying to get a session", t);
174175
}
175176
}
176177

@@ -182,7 +183,7 @@ public void onMessage(String msg) {
182183
}
183184

184185
if (debug) {
185-
log.debug(msg);
186+
log.debug("onMessage: " + msg);
186187
}
187188

188189
try {
@@ -195,8 +196,6 @@ public void onMessage(String msg) {
195196
try {
196197
processIncomingResponse(responseBase, type);
197198
} catch (Throwable t) {
198-
log.error("Failed to process response '" + type.getSimpleName() + "' from websocket.");
199-
t.printStackTrace();
200199
runOnError("Failed to process response '" + type.getSimpleName() + "' from websocket", t);
201200
}
202201

@@ -213,14 +212,10 @@ public void onMessage(String msg) {
213212
try {
214213
processIncomingEvent(msg, eventType);
215214
} catch (Throwable t) {
216-
log.error("Failed to execute callback for event: " + eventType);
217-
t.printStackTrace();
218215
runOnError("Failed to execute callback for event: " + eventType, t);
219216
}
220217
}
221218
} catch (Throwable t) {
222-
log.error("Failed to process message from websocket.");
223-
t.printStackTrace();
224219
runOnError("Failed to process message from websocket", t);
225220
}
226221
}
@@ -264,8 +259,6 @@ private void processIncomingResponse(ResponseBase responseBase, Class type) {
264259
try {
265260
callbacks.get(type).run(responseBase);
266261
} catch (Throwable t) {
267-
log.error("Failed to execute callback for response: " + type);
268-
t.printStackTrace();
269262
runOnError("Failed to execute callback for response: " + type, t);
270263
}
271264
}
@@ -330,7 +323,6 @@ private void processIncomingEvent(String msg, EventType eventType) {
330323

331324
private void authenticateWithServer(String challenge, String salt) {
332325
if (password == null) {
333-
log.error("Authentication required by server but no password set by client");
334326
runOnConnectionFailed("Authentication required by server but no password set by client");
335327
return;
336328
}
@@ -352,8 +344,6 @@ private String generateAuthenticationResponseString(String challenge, String sal
352344
try {
353345
digest = MessageDigest.getInstance("SHA-256");
354346
} catch (NoSuchAlgorithmException e) {
355-
log.error("Failed to perform password authentication with server");
356-
e.printStackTrace();
357347
runOnConnectionFailed("Failed to perform password authentication with server");
358348
return null;
359349
}
@@ -645,41 +635,44 @@ public void setStudioModeEnabled(boolean enabled, Callback callback) {
645635
}
646636

647637
private void runOnError(String message, Throwable throwable) {
638+
log.debug("Running onError with message: " + message + " and exception:", throwable);
648639
if (onError == null) {
640+
log.debug("No onError callback was registered");
649641
return;
650642
}
651643

652644
try {
653645
onError.run(message, throwable);
654646
} catch (Throwable t) {
655-
log.error("Exception during callback execution for 'onError'");
656-
t.printStackTrace();
647+
log.error("Unable to run onError callback", t);
657648
}
658649
}
659650

660651
private void runOnConnectionFailed(String message) {
652+
log.debug("Running onConnectionFailed, with message: " + message);
661653
if (onConnectionFailed == null) {
654+
log.debug("No onConnectionFailed callback was registered");
662655
return;
663656
}
664657

665658
try {
666659
onConnectionFailed.run(message);
667660
} catch (Throwable t) {
668-
log.error("Exception during callback execution for 'onConnectionFailed'");
669-
t.printStackTrace();
661+
log.error("Unable to run OnConnectionFailed callback", t);
670662
}
671663
}
672664

673665
private void runOnConnect(GetVersionResponse versionInfo) {
666+
log.debug("Running onConnect with versionInfo: " + versionInfo);
674667
if (onConnect == null) {
668+
log.debug("No onConnect callback was registered");
675669
return;
676670
}
677671

678672
try {
679673
onConnect.run(versionInfo);
680674
} catch (Throwable t) {
681-
log.error("Exception during callback execution for 'onConnect'");
682-
t.printStackTrace();
675+
log.error("Unable to run OnConnect callback", t);
683676
}
684677
}
685678
}

src/main/java/net/twasi/obsremotejava/OBSRemoteController.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public void connect() {
5656
try {
5757
client.start();
5858
} catch (Exception e) {
59-
log.error("Failed to start WebSocketClient.");
60-
e.printStackTrace();
6159
runOnError("Failed to start WebSocketClient", e);
6260
return;
6361
}
@@ -66,27 +64,20 @@ public void connect() {
6664
URI uri = new URI(address);
6765
ClientUpgradeRequest request = new ClientUpgradeRequest();
6866
Future<Session> connection = client.connect(communicator, uri, request);
69-
log.info(String.format("Connecting to: %s%s.%n", uri, (password != null ? " with password" : "")));
70-
67+
log.info(String.format("Connecting to: %s%s.%n", uri, (password != null ? " with password" : " (no password)")));
7168
try {
7269
connection.get();
7370
failed = false;
7471
} catch (ExecutionException e) {
7572
if (e.getCause() instanceof ConnectException) {
76-
log.error("Failed to connect to OBS.");
77-
e.printStackTrace();
78-
7973
failed = true;
80-
81-
runOnConnectionFailed("Failed to connect to OBS");
74+
runOnConnectionFailed("Failed to connect to OBS! Is it running and is the websocket plugin installed?", e);
8275
} else {
8376
throw e;
8477
}
8578
}
8679
} catch (Throwable t) {
87-
log.error("Failed to setup connection with OBS.");
88-
t.printStackTrace();
89-
runOnConnectionFailed("Failed to setup connection with OBS");
80+
runOnConnectionFailed("Failed to setup connection with OBS", t);
9081
}
9182
}
9283

@@ -98,7 +89,6 @@ public void disconnect() {
9889
}
9990
communicator.awaitClose(1, TimeUnit.SECONDS);
10091
} catch (InterruptedException e) {
101-
e.printStackTrace();
10292
runOnError("Error during closing websocket connection", e);
10393
}
10494

@@ -109,7 +99,6 @@ public void disconnect() {
10999
}
110100
client.stop();
111101
} catch (Exception e) {
112-
e.printStackTrace();
113102
runOnError("Error during stopping websocket client", e);
114103
}
115104
}
@@ -321,26 +310,31 @@ public void saveReplayBuffer(Callback callback) {
321310
}
322311

323312
private void runOnError(String message, Throwable throwable) {
313+
log.debug("Running onError with message: " + message + " and exception:", throwable);
324314
if (onError == null) {
315+
log.debug("No onError callback was registered");
325316
return;
326317
}
327318

328319
try {
329320
onError.run(message, throwable);
330321
} catch (Exception e) {
331-
e.printStackTrace();
322+
log.error("Unable to run OnError callback", e);
332323
}
333324
}
334325

335-
private void runOnConnectionFailed(String message) {
326+
private void runOnConnectionFailed(String message, Throwable throwable) {
327+
log.debug("Running onConnectionFailed with message: " + message + " with exception:", throwable);
328+
336329
if (onConnectionFailed == null) {
330+
log.debug("No onConnectionFailed callback was registered");
337331
return;
338332
}
339333

340334
try {
341335
onConnectionFailed.run(message);
342336
} catch (Exception e) {
343-
e.printStackTrace();
337+
log.error("Unable to run OnConnectionFailed callback", e);
344338
}
345339
}
346340
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Turning off Jetty logging.
2+
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog
3+
org.eclipse.jetty.LEVEL=OFF
4+
5+
# Default levels for the project
6+
org.slf4j.simpleLogger.defaultLogLevel=info
7+
org.slf4j.simpleLogger.log.net.twasi.obsremotejava=debug

0 commit comments

Comments
 (0)