Skip to content

Commit d2b2f4f

Browse files
authored
Merge pull request #78 from ccutrer/logging
Logging
2 parents 193b816 + ed5d16a commit d2b2f4f

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Usage
1313
Include HAP-Java in your project using maven:
1414
```
1515
<dependency>
16-
<groupId>com.beowulfe.hap</groupId>
16+
<groupId>io.github.hap-java</groupId>
1717
<artifactId>hap</artifactId>
18-
<version>1.1.3</version>
18+
<version>1.2.0-SNAPSHOT</version>
1919
</dependency>
2020
```
2121

src/main/java/io/github/hapjava/impl/http/impl/BinaryHandler.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import io.netty.buffer.Unpooled;
66
import io.netty.channel.ChannelHandlerContext;
77
import io.netty.handler.codec.ByteToMessageCodec;
8-
import java.io.ByteArrayOutputStream;
98
import java.io.IOException;
109
import java.nio.charset.StandardCharsets;
1110
import java.util.List;
12-
import org.apache.commons.io.HexDump;
1311
import org.slf4j.Logger;
1412
import org.slf4j.LoggerFactory;
1513

@@ -27,9 +25,9 @@ public BinaryHandler(HomekitClientConnection connection) {
2725
@Override
2826
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
2927
if (started) {
28+
debugData("Sending data", msg, ctx);
3029
byte[] b = new byte[msg.readableBytes()];
3130
msg.readBytes(b);
32-
traceData("Sending data", b, ctx);
3331
out.writeBytes(connection.encryptResponse(b));
3432
} else {
3533
out.writeBytes(msg);
@@ -41,8 +39,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
4139
byte[] b = new byte[in.readableBytes()];
4240
in.readBytes(b);
4341
byte[] decrypted = connection.decryptRequest(b);
44-
traceData("Received data", decrypted, ctx);
45-
out.add(Unpooled.copiedBuffer(decrypted));
42+
ByteBuf outBuf = Unpooled.copiedBuffer(decrypted);
43+
debugData("Received data", outBuf, ctx);
44+
out.add(outBuf);
4645
started = true;
4746
}
4847

@@ -57,18 +56,12 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
5756
super.exceptionCaught(ctx, cause);
5857
}
5958

60-
private void traceData(String msg, byte[] b, ChannelHandlerContext ctx) throws Exception {
61-
if (logger.isTraceEnabled() && b.length > 0) {
62-
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
63-
HexDump.dump(b, 0, stream, 0);
64-
stream.flush();
65-
logger.trace(
66-
String.format(
67-
"%s [%s]:%n%s%n",
68-
msg,
69-
ctx.channel().remoteAddress().toString(),
70-
stream.toString(StandardCharsets.UTF_8.name())));
71-
}
59+
private void debugData(String msg, ByteBuf b, ChannelHandlerContext ctx) throws Exception {
60+
if (logger.isDebugEnabled()) {
61+
logger.debug(
62+
String.format(
63+
"%s [%s]:%n%s",
64+
msg, ctx.channel().remoteAddress().toString(), b.toString(StandardCharsets.UTF_8)));
7265
}
7366
}
7467
}

0 commit comments

Comments
 (0)