Difference between revisions of "Debugging"

From wiki.vg
Jump to navigation Jump to search
(Include fix for https://bugs.mojang.com/browse/MC-100524 by default (especially in debug logs this is important))
(Partial rewrite (will expand later))
Line 1: Line 1:
Minecraft's client and server can log every packet which can be helpful for debugging.  It can also log a large amount of other information should it be necessary, beyond what is normally found in the logs.
+
The Notchian client and server (and additionally the launcher) can generate additional log information that what is normally displayed, some of which is extremely helpful for debugging.  This can be done by specifying a custom [http://logging.apache.org/log4j/2.x/manual/configuration.html Log4j configuration] by supplying a <code>-Dlog4j.configurationFile=fullpathtoconfigfile.xml</code> argument to the game:
  
    -Dlog4j.configurationFile=fullpathtoconfigfile.xml
 
 
The <code>-Dlog4j.configurationFile=fullpathtoconfigfile.xml</code> should be placed:
 
 
* [[media:ClientDebugging.png|In the JVM Arguments section of the launcher]]
 
* [[media:ClientDebugging.png|In the JVM Arguments section of the launcher]]
 
* Before the <code>-jar</code> in the server launch command
 
* Before the <code>-jar</code> in the server launch command
 +
* Before the <code>-jar</code> when directly invoking the <code>launcher.jar</code>
 +
 +
{{Warning|If the configuration specified with <code>-Dlog4j.configurationFile</code> cannot be found, the default one will silently be used instead.}}
 +
 +
You can get the default configuration for the game by extracting <code>log4j2.xml</code> from the jar you wish to work with. 
 +
 +
== Options ==
 +
 +
The main settings that are worth modifying is the value of <code>level</code> in <code>Root</code>, and the list of <code>filter</code>s.  (SOUNDS, NETWORK, NETWORK_PACKETS, PACKET_SENT, PACKET_RECEIVED)
 +
 +
== Sample configs ==
 +
 +
=== Network packets only ===
 +
 +
''Applies to: vanilla client and server''
 +
 +
Produces logs of all packets sent to and from the server/client, '''and nothing else''' (this also disables logging of normal content, including chat).  Unfortunately, since the Netty rewrite (Minecraft 1.7) only packet IDs and classes are logged, and not their contents; however, this information may still be helpful.
 +
 +
{{warning|Packet IDs are shown in decimal in logs; they are not in hexadecimal.}}
  
where the config file should contain
+
<div class="mw-collapsible mw-collapsed" style="border: 1px solid #aaa;">
<syntaxhighlight lang="xml">
+
Config:
 +
<syntaxhighlight lang="xml" class="mw-collapsible-content">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="net.minecraft,com.mojang">
+
<Configuration status="WARN" packages="com.mojang.util">
 
     <Appenders>
 
     <Appenders>
 
         <Console name="SysOut" target="SYSTEM_OUT">
 
         <Console name="SysOut" target="SYSTEM_OUT">
Line 24: Line 41:
 
                 <OnStartupTriggeringPolicy />
 
                 <OnStartupTriggeringPolicy />
 
             </Policies>
 
             </Policies>
             <DefaultRolloverStrategy max="999999"/>
+
             <DefaultRolloverStrategy max="1000"/>
 
         </RollingRandomAccessFile>
 
         </RollingRandomAccessFile>
 
     </Appenders>
 
     </Appenders>
Line 30: Line 47:
 
         <Root level="debug">
 
         <Root level="debug">
 
             <filters>
 
             <filters>
                 <MarkerFilter marker="NETWORK_PACKETS" onMatch="ACCEPT" onMismatch="NEUTRAL" />
+
                 <MarkerFilter marker="NETWORK_PACKETS" onMatch="ACCEPT" onMismatch="DENY" />
 
             </filters>
 
             </filters>
 
             <AppenderRef ref="SysOut"/>
 
             <AppenderRef ref="SysOut"/>
Line 39: Line 56:
 
</Configuration>
 
</Configuration>
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</div>
  
Doing this will display some packet information in the console.  Unfortunately after the netty rewrite (1.7), only packet names and IDs are shown; packet content is no longer given.  Nevertheless, this information still can be useful.
+
=== All debug information ===
  
{{warning|Packet IDs are shown in decimal in logs; they are not in hexadecimal.}}
+
''Applies to: vanilla client and server''
  
<pre>
+
You can log even more information if you want. This will print normal log messages (such as chat), but also network packets, sounds starting/stopping playing (client only), some authentication requests, and other miscellaneous information.
[08:21:44] [Netty Client IO #0/DEBUG]: OUT: [HANDSHAKING:0] jd
 
[08:21:44] [Netty Client IO #0/DEBUG]: OUT: [STATUS:0] jw
 
[08:21:44] [Netty Client IO #0/DEBUG]:  IN: [STATUS:0] js
 
[08:21:44] [Netty Client IO #0/DEBUG]: OUT: [STATUS:1] jv
 
[08:21:44] [Netty Client IO #0/DEBUG]:  IN: [STATUS:1] jr
 
[08:21:52] [Netty Client IO #1/DEBUG]: OUT: [HANDSHAKING:0] jd
 
[08:21:52] [Netty Client IO #1/DEBUG]: OUT: [LOGIN:0] jm
 
[08:21:52] [Netty Client IO #1/DEBUG]: IN: [LOGIN:1] ji
 
</pre>
 
  
Minecraft can do even more logging should you need it, if you allow it to log all sections.
+
<div class="mw-collapsible mw-collapsed" style="border: 1px solid #aaa;">
 
+
Config:
<syntaxhighlight lang="xml">
+
<syntaxhighlight lang="xml" class="mw-collapsible-content">
 +
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="net.minecraft,com.mojang">
+
<Configuration status="WARN" packages="com.mojang.util">
 
     <Appenders>
 
     <Appenders>
 
         <Console name="SysOut" target="SYSTEM_OUT">
 
         <Console name="SysOut" target="SYSTEM_OUT">
Line 73: Line 83:
 
                 <OnStartupTriggeringPolicy />
 
                 <OnStartupTriggeringPolicy />
 
             </Policies>
 
             </Policies>
            <DefaultRolloverStrategy max="999999"/>
 
 
         </RollingRandomAccessFile>
 
         </RollingRandomAccessFile>
 
     </Appenders>
 
     </Appenders>
Line 82: Line 91:
 
             <AppenderRef ref="ServerGuiConsole"/>
 
             <AppenderRef ref="ServerGuiConsole"/>
 
         </Root>
 
         </Root>
     </Loggers>  
+
     </Loggers>
 
</Configuration>
 
</Configuration>
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</div>
  
This will give you information about networking, sounds, authentication, and several other categories.
+
=== All debug information on CraftBukkit/Spigot ===
 +
 
 +
''Applies to: CraftBukkit servers and servers that derive from CraftBukkit''
 +
 
 +
Because CraftBukkit uses slightly different console output (and has no server GUI), the configuration needs to be slightly tweaked to display correctly.  However, doing this will also display the remapped packet class names.
 +
 
 +
<div class="mw-collapsible mw-collapsed" style="border: 1px solid #aaa;">
 +
Config:
 +
<syntaxhighlight lang="xml" class="mw-collapsible-content">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<Configuration status="WARN" packages="net.minecraft,com.mojang">
 +
    <Appenders>
 +
        <Console name="WINDOWS_COMPAT" target="SYSTEM_OUT"></Console>
 +
        <Queue name="TerminalConsole">
 +
            <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
 +
        </Queue>
 +
        <RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
 +
            <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
 +
            <Policies>
 +
                <TimeBasedTriggeringPolicy />
 +
                <OnStartupTriggeringPolicy />
 +
            </Policies>
 +
        </RollingRandomAccessFile>
 +
    </Appenders>
 +
    <Loggers>
 +
        <Root level="debug">
 +
            <AppenderRef ref="WINDOWS_COMPAT"/>
 +
            <AppenderRef ref="File"/>
 +
            <AppenderRef ref="TerminalConsole"/>
 +
        </Root>
 +
    </Loggers>
 +
</Configuration>
 +
</syntaxhighlight>
 +
</div>

Revision as of 21:00, 1 November 2016

The Notchian client and server (and additionally the launcher) can generate additional log information that what is normally displayed, some of which is extremely helpful for debugging. This can be done by specifying a custom Log4j configuration by supplying a -Dlog4j.configurationFile=fullpathtoconfigfile.xml argument to the game:

Warning.png If the configuration specified with -Dlog4j.configurationFile cannot be found, the default one will silently be used instead.

You can get the default configuration for the game by extracting log4j2.xml from the jar you wish to work with.

Options

The main settings that are worth modifying is the value of level in Root, and the list of filters. (SOUNDS, NETWORK, NETWORK_PACKETS, PACKET_SENT, PACKET_RECEIVED)

Sample configs

Network packets only

Applies to: vanilla client and server

Produces logs of all packets sent to and from the server/client, and nothing else (this also disables logging of normal content, including chat). Unfortunately, since the Netty rewrite (Minecraft 1.7) only packet IDs and classes are logged, and not their contents; however, this information may still be helpful.

Warning.png Packet IDs are shown in decimal in logs; they are not in hexadecimal.

Config:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="com.mojang.util">
    <Appenders>
        <Console name="SysOut" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
        </Console>
        <Queue name="ServerGuiConsole">
            <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
        </Queue>
        <RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
            <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <OnStartupTriggeringPolicy />
            </Policies>
            <DefaultRolloverStrategy max="1000"/>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <filters>
                <MarkerFilter marker="NETWORK_PACKETS" onMatch="ACCEPT" onMismatch="DENY" />
            </filters>
            <AppenderRef ref="SysOut"/>
            <AppenderRef ref="File"/>
            <AppenderRef ref="ServerGuiConsole"/>
        </Root>
    </Loggers> 
</Configuration>

All debug information

Applies to: vanilla client and server

You can log even more information if you want. This will print normal log messages (such as chat), but also network packets, sounds starting/stopping playing (client only), some authentication requests, and other miscellaneous information.

Config:

<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="com.mojang.util">
    <Appenders>
        <Console name="SysOut" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
        </Console>
        <Queue name="ServerGuiConsole">
            <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
        </Queue>
        <RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
            <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <OnStartupTriggeringPolicy />
            </Policies>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="SysOut"/>
            <AppenderRef ref="File"/>
            <AppenderRef ref="ServerGuiConsole"/>
        </Root>
    </Loggers>
</Configuration>

All debug information on CraftBukkit/Spigot

Applies to: CraftBukkit servers and servers that derive from CraftBukkit

Because CraftBukkit uses slightly different console output (and has no server GUI), the configuration needs to be slightly tweaked to display correctly. However, doing this will also display the remapped packet class names.

Config:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="net.minecraft,com.mojang">
    <Appenders>
        <Console name="WINDOWS_COMPAT" target="SYSTEM_OUT"></Console>
        <Queue name="TerminalConsole">
            <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
        </Queue>
        <RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
            <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <OnStartupTriggeringPolicy />
            </Policies>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="WINDOWS_COMPAT"/>
            <AppenderRef ref="File"/>
            <AppenderRef ref="TerminalConsole"/>
        </Root>
    </Loggers>
</Configuration>