Skip to content

Commit

Permalink
Add embedded logging configs
Browse files Browse the repository at this point in the history
Minecraft's default logging configs output XML to stdout, because the
modern launcher parses it to provide a "nicer" console. We don't do
that, so this commit adds embedded versions of the logging configs which
just output log lines normally.
  • Loading branch information
hedgehog1029 committed Dec 31, 2021
1 parent 94ae835 commit 6f7624a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.logging.Level;

Expand Down Expand Up @@ -274,18 +277,28 @@ protected void installLibraries(@NonNull Installer installer,
}
}

// Fetch logging config
// Use our custom logging config depending on what the manifest specifies
if (versionManifest.getLogging() != null) {
VersionManifest.LoggingConfig config = versionManifest.getLogging().getClient();

VersionManifest.Artifact file = config.getFile();
File targetFile = new File(librariesDir, file.getId());
InputStream embeddedConfig = Launcher.class.getResourceAsStream("logging/" + file.getId());

if (!targetFile.exists() || !Objects.equals(config.getFile().getHash(), FileUtils.getShaHash(targetFile))) {
if (embeddedConfig == null) {
// No embedded config, just use whatever the server gives us
File tempFile = installer.getDownloader().download(url(file.getUrl()), file.getHash(), file.getSize(), file.getId());

log.info("Downloading logging config " + file.getId() + " from " + file.getUrl());
installer.queue(new FileMover(tempFile, targetFile));
} else if (!targetFile.exists() || FileUtils.getShaHash(targetFile).equals(file.getHash())) {
// Use our embedded replacement

Path tempFile = installer.getTempDir().toPath().resolve(file.getId());
Files.copy(embeddedConfig, tempFile);

log.info("Substituting embedded logging config " + file.getId());
installer.queue(new FileMover(tempFile.toFile(), targetFile));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="SysOut" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg{nolookups}%n"/>
</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{nolookups}%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<OnStartupTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="info">
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
</filters>
<AppenderRef ref="SysOut"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="SysOut" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n"/>
</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>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="info">
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
<RegexFilter regex=".*\$\{[^}]*\}.*" onMatch="DENY" onMismatch="NEUTRAL"/>
</filters>
<AppenderRef ref="SysOut"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>

0 comments on commit 6f7624a

Please sign in to comment.