Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup logging #193

Open
wants to merge 2 commits into
base: Multiloader-1.20.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions common/src/main/java/org/vivecraft/MixinConfig.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.vivecraft;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.service.MixinService;
import org.vivecraft.client.Xplat;
import org.vivecraft.common.utils.Utils;
import org.vivecraft.mod_compat_vr.iris.mixin.IrisChunkProgramOverridesMixinSodium_0_4_11;
import org.vivecraft.mod_compat_vr.iris.mixin.IrisChunkProgramOverridesMixinSodium_0_4_9;
import org.vivecraft.mod_compat_vr.sodium.mixin.RenderSectionManagerVRMixin;
Expand Down Expand Up @@ -50,7 +49,7 @@ public void onLoad(String mixinPackage) {
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (!Xplat.isModLoadedSuccess()) {
LogManager.getLogger().log(Level.WARN, "not loading '" + mixinClassName + "' because mod failed to load completely");
Utils.logger.warn("not loading '{}' because mod failed to load completely", mixinClassName);
return false;
}

Expand All @@ -76,7 +75,7 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
MixinService.getService().getBytecodeProvider().getClassNode(neededClass);
return true;
} catch (ClassNotFoundException | IOException e) {
LogManager.getLogger().log(Level.INFO, "Vivecraft: skipping mixin '" + mixinClassName + "'");
Utils.logger.info("skipping mixin '{}'", mixinClassName);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.phys.Vec3;
import org.vivecraft.client.VRPlayersClient;
import org.vivecraft.client.Xplat;
import org.vivecraft.client.utils.Utils;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.VRState;
import org.vivecraft.client_vr.gameplay.VRPlayer;
Expand Down Expand Up @@ -226,10 +227,10 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI
&& (dataholder.vrSettings.showServerPluginMessage == VRSettings.ChatServerPluginMessage.ALWAYS
|| (dataholder.vrSettings.showServerPluginMessage == VRSettings.ChatServerPluginMessage.SERVER_ONLY && !Minecraft.getInstance().isLocalServer()))) {
ClientNetworking.displayedChatMessage = true;
mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.serverplugin", s11));
Utils.printChatMessage(Component.translatable("vivecraft.messages.serverplugin", s11));
}
if (VRState.vrEnabled && dataholder.vrSettings.manualCalibration == -1.0F && !dataholder.vrSettings.seated) {
mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.calibrateheight"));
Utils.printChatMessage(Component.translatable("vivecraft.messages.calibrateheight"));
}
}
case IS_VR_ACTIVE -> {
Expand Down Expand Up @@ -299,7 +300,7 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI
}
}

System.out.println("Server setting override: " + s13 + " = " + s14);
org.vivecraft.common.utils.Utils.logger.info("Server setting override: {} = {}", s13, s14);
} catch (Exception exception) {
exception.printStackTrace();
}
Expand All @@ -313,7 +314,7 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI
ClientNetworking.serverAllowsVrSwitching = buffer.readBoolean();
if (VRState.vrInitialized) {
if (!ClientNetworking.serverAllowsVrSwitching) {
Minecraft.getInstance().gui.getChat().addMessage(Component.translatable("vivecraft.messages.novrhotswitching"));
Utils.printChatMessage(Component.translatable("vivecraft.messages.novrhotswitching"));
}
dataholder.vrPlayer.vrSwitchWarning = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ private static void fileDownloadFinished(String url, String data) {
}
}
} catch (Exception exception1) {
System.out.println("error with donors txt " + exception1.getMessage());
org.vivecraft.common.utils.Utils.logger.error("error with donors txt {}", exception1.getMessage());
}
}

cache = hashmap;
} catch (Exception exception1) {
System.out.println("Error parsing data: " + url + ", " + exception1.getClass().getName() + ": " + exception1.getMessage());
org.vivecraft.common.utils.Utils.logger.error("Error parsing data: {}, {}: {}", url, exception1.getClass().getName(), exception1.getMessage());
downloadFailed = true;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.logging.LogUtils;
import net.minecraft.SharedConstants;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.common.utils.Utils;
import org.vivecraft.server.config.ServerConfig;

import java.io.BufferedReader;
Expand All @@ -29,7 +29,7 @@ public class UpdateChecker {
public static String newestVersion = "";

public static boolean checkForUpdates() {
System.out.println("Checking for Vivecraft Updates");
Utils.logger.info("Checking for Updates...");

char updateType;
if (Xplat.isDedicatedServer()) {
Expand All @@ -54,7 +54,7 @@ public static boolean checkForUpdates() {
conn.connect();

if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
LogUtils.getLogger().error("Error " + conn.getResponseCode() + " fetching Vivecraft updates");
Utils.logger.error("Error {} fetching updates!", conn.getResponseCode());
return false;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public static boolean checkForUpdates() {
// no carriage returns please
changelog = changelog.replaceAll("\\r", "");
if (hasUpdate) {
LogUtils.getLogger().info("Vivecraft update found: " + newestVersion);
Utils.logger.info("Update found!: {}", newestVersion);
}
} catch (IOException e) {
e.printStackTrace();
Expand Down
60 changes: 19 additions & 41 deletions common/src/main/java/org/vivecraft/client/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.openvr.HmdMatrix44;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.render.VRShaders;
Expand Down Expand Up @@ -50,6 +50,13 @@ public class Utils {
private static final int READ_TIMEOUT = 20000;
private static final Random avRandomizer = new Random();

public static void printChatMessage(final Component literal) {
Minecraft mc = Minecraft.getInstance();
if (mc.level != null) {
mc.gui.getChat().addMessage(literal);
}
}

public static String sanitizeFileName(String fileName) {
StringBuilder stringbuilder = new StringBuilder();

Expand Down Expand Up @@ -334,7 +341,7 @@ private static void handleAssetException(Throwable e, String name, boolean requi
if (required) {
throw new RuntimeException("Failed to load asset: " + name, e);
} else {
System.out.println("Failed to load asset: " + name);
org.vivecraft.common.utils.Utils.logger.error("Failed to load asset: {}", name);
e.printStackTrace();
}
}
Expand All @@ -352,10 +359,10 @@ public static void unpackNatives(String directory) {
}

if (path1.toFile().exists()) {
System.out.println("Copying " + directory + " natives...");
org.vivecraft.common.utils.Utils.logger.info("Copying {} natives...", directory);

for (File file1 : path1.toFile().listFiles()) {
System.out.println(file1.getName());
org.vivecraft.common.utils.Utils.logger.info(file1.getName());
Files.copy(file1, new File("openvr/" + directory + "/" + file1.getName()));
}

Expand All @@ -364,18 +371,18 @@ public static void unpackNatives(String directory) {
} catch (Exception exception) {
}

System.out.println("Unpacking " + directory + " natives...");
org.vivecraft.common.utils.Utils.logger.info("Unpacking {} natives...", directory);

Path jarPath = Xplat.getJarPath();
boolean didExtractSomething = false;
try (Stream<Path> natives = java.nio.file.Files.list(jarPath.resolve("natives/" + directory))) {
for (Path file : natives.collect(Collectors.toCollection(ArrayList::new))) {
didExtractSomething = true;
System.out.println(file);
org.vivecraft.common.utils.Utils.logger.info(file.toString());
java.nio.file.Files.copy(file, new File("openvr/" + directory + "/" + file.getFileName()).toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
System.out.println("Failed to unpack natives from jar");
org.vivecraft.common.utils.Utils.logger.error("Failed to unpack natives from jar");
}
if (!didExtractSomething) {
ZipFile zipfile = LoaderUtils.getVivecraftZip();
Expand All @@ -386,15 +393,15 @@ public static void unpackNatives(String directory) {

if (zipentry.getName().startsWith("natives/" + directory)) {
String s = Paths.get(zipentry.getName()).getFileName().toString();
System.out.println(s);
org.vivecraft.common.utils.Utils.logger.info(s);
writeStreamToFile(zipfile.getInputStream(zipentry), new File("openvr/" + directory + "/" + s));
}
}

zipfile.close();
}
} catch (Exception exception1) {
System.out.println("Failed to unpack natives");
org.vivecraft.common.utils.Utils.logger.error("Failed to unpack natives");
exception1.printStackTrace();
}
}
Expand Down Expand Up @@ -627,7 +634,7 @@ public static void spawnParticles(ParticleOptions type, int count, Vec3 position
try {
minecraft.level.addParticle(type, position.x + d0, position.y + d1, position.z + d2, d3, d4, d5);
} catch (Throwable throwable) {
LogManager.getLogger().warn("Could not spawn particle effect {}", type);
org.vivecraft.common.utils.Utils.logger.warn("Could not spawn particle effect {}", type);
return;
}
}
Expand All @@ -646,13 +653,8 @@ public static int getCombinedLightWithMin(BlockAndTintGetter lightReader, BlockP
}

public static void takeScreenshot(RenderTarget fb) {
Minecraft minecraft = Minecraft.getInstance();
Screenshot.grab(minecraft.gameDirectory, fb, (text) ->
{
minecraft.execute(() -> {
minecraft.gui.getChat().addMessage(text);
});
});
Minecraft mc = Minecraft.getInstance();
Screenshot.grab(mc.gameDirectory, fb, (text) -> mc.execute(() -> printChatMessage(text)));
}

public static List<FormattedText> wrapText(FormattedText text, int width, Font fontRenderer, @Nullable FormattedText linePrefix) {
Expand Down Expand Up @@ -718,30 +720,6 @@ public static String styleToFormatString(Style style) {
return formatsToString(styleToFormats(style));
}

public static long microTime() {
return System.nanoTime() / 1000L;
}

public static long milliTime() {
return System.nanoTime() / 1000000L;
}

public static void printStackIfContainsClass(String className) {
StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace();
boolean flag = false;

for (StackTraceElement stacktraceelement : astacktraceelement) {
if (stacktraceelement.getClassName().equals(className)) {
flag = true;
break;
}
}

if (flag) {
Thread.dumpStack();
}
}

public static org.joml.Matrix4f Matrix4fFromOpenVR(HmdMatrix44 in) {
return new org.joml.Matrix4f(in.m(0), in.m(4), in.m(8), in.m(12),
in.m(1), in.m(5), in.m(9), in.m(13),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,4 @@ public static ClientDataHolderVR getInstance() {
}
return INSTANCE;
}

public void printChatMessage(String string) {
// TODO Auto-generated method stub

}

public void print(String string) {
string = string.replace("\n", "\n[Minecrift] ");
System.out.println("[Minecrift] " + string);
}
}
23 changes: 14 additions & 9 deletions common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ public VRTextureTarget(String name, int width, int height, boolean usedepth, boo

@Override
public String toString() {
StringBuilder stringbuilder = new StringBuilder();
stringbuilder.append("\n");
if (this.name != null) {
stringbuilder.append("Name: " + this.name).append("\n");
}
stringbuilder.append("Size: " + this.viewWidth + " x " + this.viewHeight).append("\n");
stringbuilder.append("FB ID: " + this.frameBufferId).append("\n");
stringbuilder.append("Tex ID: " + this.colorTextureId).append("\n");
return stringbuilder.toString();
return
"""
Texture Target:
Name: %s
Size: %d x %d
FB ID: %d
Tex ID: %d
""".formatted(
this.name,
this.viewWidth,
this.viewHeight,
this.frameBufferId,
this.colorTextureId
);
}
}
Loading