Skip to content

Commit 5090ca4

Browse files
Add log marker for packet logging
1 parent c36d179 commit 5090ca4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

protocol/src/main/java/org/geysermc/mcprotocollib/network/tcp/TcpPacketCodec.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
import org.geysermc.mcprotocollib.network.packet.PacketRegistry;
1515
import org.slf4j.Logger;
1616
import org.slf4j.LoggerFactory;
17+
import org.slf4j.Marker;
18+
import org.slf4j.MarkerFactory;
1719

1820
import java.util.List;
1921

2022
public class TcpPacketCodec extends MessageToMessageCodec<ByteBuf, Packet> {
23+
private static final Marker marker = MarkerFactory.getMarker("packet_logging");
2124
private static final Logger log = LoggerFactory.getLogger(TcpPacketCodec.class);
2225

2326
private final Session session;
@@ -32,7 +35,7 @@ public TcpPacketCodec(Session session, boolean client) {
3235
@Override
3336
public void encode(ChannelHandlerContext ctx, Packet packet, List<Object> out) {
3437
if (log.isTraceEnabled()) {
35-
log.trace("Encoding packet: {}", packet.getClass().getSimpleName());
38+
log.trace(marker, "Encoding packet: {}", packet.getClass().getSimpleName());
3639
}
3740

3841
PacketProtocol packetProtocol = this.session.getPacketProtocol();
@@ -49,10 +52,10 @@ public void encode(ChannelHandlerContext ctx, Packet packet, List<Object> out) {
4952
out.add(buf);
5053

5154
if (log.isDebugEnabled()) {
52-
log.debug("Encoded packet {} ({})", packet.getClass().getSimpleName(), packetId);
55+
log.debug(marker, "Encoded packet {} ({})", packet.getClass().getSimpleName(), packetId);
5356
}
5457
} catch (Throwable t) {
55-
log.debug("Error encoding packet", t);
58+
log.debug(marker, "Error encoding packet", t);
5659

5760
PacketErrorEvent e = new PacketErrorEvent(this.session, t);
5861
this.session.callEvent(e);
@@ -82,7 +85,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out)
8285
return;
8386
}
8487

85-
log.trace("Decoding packet with id: {}", id);
88+
log.trace(marker, "Decoding packet with id: {}", id);
8689

8790
packet = this.client ? packetRegistry.createClientboundPacket(id, buf, codecHelper) : packetRegistry.createServerboundPacket(id, buf, codecHelper);
8891

@@ -93,10 +96,10 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out)
9396
out.add(packet);
9497

9598
if (log.isDebugEnabled()) {
96-
log.debug("Decoded packet {} ({})", packet.getClass().getSimpleName(), id);
99+
log.debug(marker, "Decoded packet {} ({})", packet.getClass().getSimpleName(), id);
97100
}
98101
} catch (Throwable t) {
99-
log.debug("Error decoding packet", t);
102+
log.debug(marker, "Error decoding packet", t);
100103

101104
// Advance buffer to end to make sure remaining data in this packet is skipped.
102105
buf.readerIndex(buf.readerIndex() + buf.readableBytes());

0 commit comments

Comments
 (0)