Skip to content

Commit

Permalink
Move packet logging behind debug (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Jun 6, 2024
2 parents 7eb8049 + ff54645 commit 362ae8a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, EntityEventPa
int event = buffer.readUnsignedByte();
packet.setType(this.typeMap.getType(event));
packet.setData(VarInts.readInt(buffer));
if (packet.getType() == null) {
if (log.isDebugEnabled() && packet.getType() == null) {
log.debug("Unknown EntityEvent {} in packet {}", event, packet);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ public ItemData readItemInstance(ByteBuf buffer) {
throw new IllegalStateException("Unable to read item user data", e);
}

if (buf.isReadable()) {
log.info("Item user data has {} readable bytes left", buf.readableBytes());
if (log.isDebugEnabled()) {
log.debug("Item data:\n{}", ByteBufUtil.prettyHexDump(buf.readerIndex(0)));
}
if (log.isDebugEnabled() && buf.isReadable()) {
log.debug("Item user data has {} readable bytes left", buf.readableBytes());
log.debug("Item data:\n{}", ByteBufUtil.prettyHexDump(buf.readerIndex(0)));
}

return ItemData.builder()
Expand Down Expand Up @@ -153,6 +151,7 @@ public ItemData readItem(ByteBuf buffer) {

if (buf.isReadable()) {
log.info("Item user data has {} readable bytes left", buf.readableBytes());

if (log.isDebugEnabled()) {
log.debug("Item data:\n{}", ByteBufUtil.prettyHexDump(buf.readerIndex(0)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cloudburstmc.protocol.bedrock.packet;

import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -23,8 +21,6 @@
@EqualsAndHashCode(doNotUseGetters = true)
@ToString(doNotUseGetters = true, exclude = {"itemDefinitions", "blockPalette"})
public class StartGamePacket implements BedrockPacket {
private static final InternalLogger log = InternalLoggerFactory.getInstance(StartGamePacket.class);

private final List<GameRuleData<?>> gamerules = new ObjectArrayList<>();
private long uniqueEntityId;
private long runtimeEntityId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,15 @@ protected void onClose() {
protected void onPacket(BedrockPacketWrapper wrapper) {
BedrockPacket packet = wrapper.getPacket();
this.logInbound(packet);

if (packetHandler == null) {
log.warn("Received packet without a packet handler for {}:{}: {}", this.getSocketAddress(), this.subClientId, packet);
if (log.isDebugEnabled()) {
log.debug("Received packet without a packet handler for {}:{}: {}", this.getSocketAddress(), this.subClientId, packet);
}
} else if (this.packetHandler.handlePacket(packet) == PacketSignal.UNHANDLED) {
log.warn("Unhandled packet for {}:{}: {}", this.getSocketAddress(), this.subClientId, packet);
if (log.isDebugEnabled()) {
log.debug("Unhandled packet for {}:{}: {}", this.getSocketAddress(), this.subClientId, packet);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.cloudburstmc.protocol.bedrock.netty.BedrockBatchWrapper;
import org.cloudburstmc.protocol.bedrock.netty.BedrockPacketWrapper;
import org.cloudburstmc.protocol.common.util.VarInts;
Expand All @@ -18,8 +16,6 @@ public class BedrockBatchEncoder extends ChannelOutboundHandlerAdapter {

public static final String NAME = "bedrock-batch-encoder";

private static final InternalLogger log = InternalLoggerFactory.getInstance(BedrockBatchEncoder.class);

private final Queue<BedrockPacketWrapper> messages = new ArrayDeque<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.util.Attribute;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.cloudburstmc.protocol.bedrock.PacketDirection;
Expand Down Expand Up @@ -52,7 +51,9 @@ protected final void encode(ChannelHandlerContext ctx, BedrockPacketWrapper msg,
msg.setPacketBuffer(buf.retain());
out.add(msg.retain());
} catch (Throwable t) {
log.error("Error encoding packet {}", msg.getPacket(), t);
if (log.isDebugEnabled()) {
log.debug("Error encoding packet {}", msg.getPacket(), t);
}
} finally {
buf.release();
}
Expand All @@ -70,7 +71,9 @@ protected final void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object>
wrapper.setPacket(this.codec.tryDecode(helper, msg, wrapper.getPacketId(), this.inboundRecipient));
out.add(wrapper.retain());
} catch (Throwable t) {
log.info("Failed to decode packet", t);
if (log.isDebugEnabled()) {
log.debug("Failed to decode packet", t);
}
throw t;
} finally {
wrapper.release();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cloudburstmc.protocol.common.util;

import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
Expand All @@ -20,8 +18,6 @@

public final class TypeMap<T> {

private static final InternalLogger log = InternalLoggerFactory.getInstance(TypeMap.class);

private final String type;
private final Object2IntMap<T> toId;
private final Int2ObjectMap<T> toObject;
Expand Down

0 comments on commit 362ae8a

Please sign in to comment.