1
0
mirror of synced 2026-08-05 15:06:54 +00:00

feat: support channel logging (#410)

This commit is contained in:
Yury Semikhatsky
2021-04-23 14:25:32 -07:00
committed by GitHub
parent 21a7f4da02
commit 8ee5b8b436
@@ -67,6 +67,7 @@ public class Connection {
private int lastId = 0;
private final Path srcDir;
private final Map<Integer, WaitableResult<JsonElement>> callbacks = new HashMap<>();
private final boolean isLogging = "pw:channel".equals(System.getenv("DEBUG"));
class Root extends ChannelOwner {
Root(Connection connection) {
@@ -153,7 +154,11 @@ public class Connection {
metadata.add("stack", currentStackTrace());
message.add("metadata", metadata);
}
transport.send(gson().toJson(message));
String messageString = gson().toJson(message);
if (isLogging) {
System.err.println("SEND ► " + messageString);
}
transport.send(messageString);
return result;
}
@@ -184,6 +189,9 @@ public class Connection {
if (messageString == null) {
return;
}
if (isLogging) {
System.err.println("◀ RECV " + messageString);
}
Gson gson = gson();
Message message = gson.fromJson(messageString, Message.class);
dispatch(message);