Zh:Debugging

From wiki.vg
Revision as of 08:04, 17 November 2019 by Kaniol (talk | contribs) (Created page with "Notch的客户端和服务端(以及启动器)可以生成除平常显示的额外日志信息,其中的一些对调试非常有帮助。要完成这个,需要通过...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Notch的客户端和服务端(以及启动器)可以生成除平常显示的额外日志信息,其中的一些对调试非常有帮助。要完成这个,需要通过指定一个自定义Log4j配置

本地启动器直接提供了一个“日志配置”部分来完成这个。对于其他情况,可以通过向游戏添加-Dlog4j.configurationFile=fullpathtoconfigfile.xml参数来完成:

当使用本地启动器时,使用日志配置的XML变体并勾选“自定义日志配置输出XML”。这会允许启动器在其输出中提供更干净的的信息。当使用java启动器或启动服务端时,使用非XML变体(你在控制台中不需要XML,且XML变体不适用于服务端GUI)。

Warning.png 如果不能找到指定了-Dlog4j.configurationFile的配置,那么将会使用默认的那个代替。

你可以通过解压要工作的jar中的log4j2.xml来获取游戏的默认配置。

选项

log4j配置中只有一些选项拥有有用的行为。

最主要的一个是<Root>中的level。一般来说,它被设置为info,但它同样接受tracedebuginfowarnerroralloff。Minecraft实际上使用的最底层是debug,所以要获得最多的额外信息应该使用这个。

另一个重要的选项是<filter>列表。默认地,游戏使用<filter>过滤掉所有数据包相关的信息,它会拒绝所有标记为NETWORK_PACKETS的日志信息。你可以更改它来使过滤器反而只接受NETWORK_PACKETS而拒绝其他的一切,或者你也可以整个移除<filter>让它显示所有的信息。除NETWORK_PACKETS之外,还有一些别的日志标记:SOUNDSNETWORKPACKET_SENT以及PACKET_RECEIVEDNETWORKNETWORK_PACKETS的行为完全一样;PACKET_SENTPACKET_RECEIVED可以用于只显示一组数据包;而SOUNDS可以用于发射有关音乐通道何时开始及结束的信息(通常只在诊断音频似乎会播放两次的问题时才有用)。

另外要注意:默认地,如果一天中的日志超过7个,那么log4j会覆写旧的日志(见MC-100524)。你可以通过向<RollingRandomAccessFile>添加<DefaultRolloverStrategy max="1000"/>来禁用此行为,这使得一天最多1000个文件(这不太可能被命中——在较大的对象上使用1000,因为在较大的数量上开始出现性能命中)。

示例配置

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>

Config (XML output):

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="SysOut" target="SYSTEM_OUT">
            <XMLLayout />
        </Console>
        <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"/>
        </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"?>
<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">
            <AppenderRef ref="SysOut"/>
            <AppenderRef ref="File"/>
            <AppenderRef ref="ServerGuiConsole"/>
        </Root>
    </Loggers>
</Configuration>

Config (XML output):

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="SysOut" target="SYSTEM_OUT">
            <XMLLayout />
        </Console>
        <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">
            <AppenderRef ref="SysOut"/>
            <AppenderRef ref="File"/>
        </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>
            <DefaultRolloverStrategy max="1000"/>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="WINDOWS_COMPAT"/>
            <AppenderRef ref="File"/>
            <AppenderRef ref="TerminalConsole"/>
        </Root>
    </Loggers>
</Configuration>

Launcher session information

Applies to: Launcher.jar

By enabling debug launching on the (Java launcher's) launcher.jar, you can view connections to the Mojang API - helpful if you want to see a sample connection to each endpoint for your own account.

Note that this configuration may not work if you invoke the normal launcher EXE/JAR - instead, use it on the launcher.jar located in %appdata%\.minecraft.

Config:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="com.mojang">
    <Appenders>
        <Console name="SysOut" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
        </Console>
        <Queue name="DevelopmentConsole">
            <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
        </Queue>
        <Async name="Async">
            <AppenderRef ref="SysOut"/>
            <AppenderRef ref="DevelopmentConsole"/>
        </Async>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Async"/>
        </Root>
    </Loggers>
</Configuration>