Skip to content

Commit

Permalink
Enable debug property in Log4J config if applicable (GeyserMC#1906)
Browse files Browse the repository at this point in the history
With this commit, debug messages in Netty and Protocol will now show if debug mode is enabled in the Geyser standalone config.

There is also some small tuning to the PacketTranslatorRegistry for cleanliness and maybe some minor performance.
  • Loading branch information
Camotoy authored Feb 8, 2021
1 parent 3140d3c commit 1ec589f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import lombok.Getter;
import net.minecrell.terminalconsole.TerminalConsoleAppender;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Logger;
Expand Down Expand Up @@ -167,11 +168,6 @@ public void onEnable(boolean useGui, String configFilename) {
this.onEnable();
}

public void onEnable(boolean useGui) {
this.useGui = useGui;
this.onEnable();
}

@Override
public void onEnable() {
Logger logger = (Logger) LogManager.getRootLogger();
Expand Down Expand Up @@ -213,6 +209,9 @@ public void onEnable() {
}
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);

// Allow libraries like Protocol to have their debug information passthrough
logger.get().setLevel(geyserConfig.isDebugMode() ? Level.DEBUG : Level.INFO);

connector = GeyserConnector.start(PlatformType.STANDALONE, this);
geyserCommandManager = new GeyserCommandManager(connector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.github.steveice10.packetlib.packet.Packet;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.FileUtils;
Expand Down Expand Up @@ -89,12 +90,15 @@ public static void init() {
public <P extends T> boolean translate(Class<? extends P> clazz, P packet, GeyserSession session) {
if (!session.getUpstream().isClosed() && !session.isClosed()) {
try {
if (translators.containsKey(clazz)) {
((PacketTranslator<P>) translators.get(clazz)).translate(packet, session);
PacketTranslator<P> translator = (PacketTranslator<P>) translators.get(clazz);
if (translator != null) {
translator.translate(packet, session);
return true;
} else {
if (!IGNORED_PACKETS.contains(clazz))
if ((GeyserConnector.getInstance().getPlatformType() != PlatformType.STANDALONE || !(packet instanceof BedrockPacket)) && !IGNORED_PACKETS.contains(clazz)) {
// Other debug logs already take care of Bedrock packets for us if on standalone
GeyserConnector.getInstance().getLogger().debug("Could not find packet for " + (packet.toString().length() > 25 ? packet.getClass().getSimpleName() : packet));
}
}
} catch (Throwable ex) {
GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.network.translator.packet.failed", packet.getClass().getSimpleName()), ex);
Expand Down

0 comments on commit 1ec589f

Please sign in to comment.