Skip to content

Commit

Permalink
refactor internal logging
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Oct 29, 2024
1 parent 6fee569 commit bc34d25
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.upcraft.sparkweave.api.SparkweaveApi;
import dev.upcraft.sparkweave.api.entrypoint.MainEntryPoint;
import dev.upcraft.sparkweave.api.event.CommandEvents;
import dev.upcraft.sparkweave.api.logging.SparkweaveLoggerFactory;
import dev.upcraft.sparkweave.api.platform.ModContainer;
import dev.upcraft.sparkweave.api.platform.services.RegistryService;
import dev.upcraft.sparkweave.api.registry.RegistryHandler;
Expand All @@ -11,13 +12,15 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.Logger;

import java.util.List;
import java.util.stream.Stream;

public class SparkweaveMod implements MainEntryPoint {

public static final String MODID = "sparkweave";
private static final Logger LOGGER = SparkweaveLoggerFactory.getLogger();

@Override
public void onInitialize(ModContainer mod) {
Expand All @@ -39,4 +42,8 @@ public static List<ResourceLocation> ids(String... paths) {
Validate.notEmpty(paths, "Must provide at least 1 ID!");
return Stream.of(paths).map(SparkweaveMod::id).toList();
}

public static void onLoadComplete() {
LOGGER.debug("System initialized!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.upcraft.sparkweave.SparkweaveMod;
import dev.upcraft.sparkweave.api.SparkweaveApi;
import dev.upcraft.sparkweave.api.annotation.Mod;
import dev.upcraft.sparkweave.logging.SparkweaveLogging;
import dev.upcraft.sparkweave.api.logging.SparkweaveLoggerFactory;
import org.apache.logging.log4j.Logger;

import java.io.File;
Expand All @@ -13,7 +13,7 @@
@Mod.Context(SparkweaveMod.MODID)
public class RenderDocHelper {

private static final Logger LOGGER = SparkweaveLogging.getLogger();
private static final Logger LOGGER = SparkweaveLoggerFactory.getLogger();

public static void init() {
if(SparkweaveApi.Client.LOAD_RENDERDOC) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import dev.upcraft.sparkweave.SparkweaveMod;
import dev.upcraft.sparkweave.api.command.CommandHelper;
import dev.upcraft.sparkweave.api.command.argument.RegistryArgumentType;
import dev.upcraft.sparkweave.api.logging.SparkweaveLoggerFactory;
import dev.upcraft.sparkweave.api.platform.Services;
import dev.upcraft.sparkweave.api.serialization.CSVWriter;
import dev.upcraft.sparkweave.logging.SparkweaveLogging;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand All @@ -19,13 +19,16 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.resources.ResourceKey;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class DumpRegistryCommand {

private static final Logger LOGGER = SparkweaveLoggerFactory.getLogger();

public static void register(LiteralArgumentBuilder<CommandSourceStack> $) {
$.then(Commands.literal("dump_registries")
.requires(src -> src.hasPermission(Commands.LEVEL_OWNERS))
Expand Down Expand Up @@ -97,7 +100,7 @@ private static void saveRegistryToFile(HolderLookup.RegistryLookup<?> lookup, Pa
}
}
} catch (IOException e) {
SparkweaveLogging.getLogger().error("Failed to write registry dump for {}", lookup.key().location(), e);
LOGGER.error("Failed to write registry dump for {}", lookup.key().location(), e);
throw CommandHelper.IO_EXCEPTION.create(e.getMessage());
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package dev.upcraft.sparkweave.platform;

import dev.upcraft.sparkweave.api.logging.SparkweaveLoggerFactory;
import dev.upcraft.sparkweave.api.platform.Services;
import dev.upcraft.sparkweave.logging.SparkweaveLogging;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class DotEnv {

private static final Logger LOGGER = SparkweaveLoggerFactory.getLogger("Sparkweave Engine/DotEnv");

public static void load(Path path) {
if(!Files.isRegularFile(path)) {
return;
}
try (var reader = Files.newBufferedReader(path)) {
System.getProperties().load(reader);
} catch (IOException e) {
SparkweaveLogging.getLogger().error("Unable to load env file: {}", path.toAbsolutePath(), e);
LOGGER.error("Unable to load env file: {}", path.toAbsolutePath(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dev.upcraft.sparkweave.validation;

import dev.upcraft.sparkweave.api.SparkweaveApi;
import dev.upcraft.sparkweave.logging.SparkweaveLogging;
import dev.upcraft.sparkweave.api.logging.SparkweaveLoggerFactory;
import net.minecraft.server.Bootstrap;
import org.apache.logging.log4j.Logger;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -12,11 +13,12 @@ public class TranslationChecker {

private static final Set<String> MISSING_KEYS = new HashSet<>();
private static final Set<String> MISSING_KEYS_VIEW = Collections.unmodifiableSet(MISSING_KEYS);
private static final Logger LOGGER = SparkweaveLoggerFactory.getLogger("Sparkweave Engine/TranslationChecker");

private static void notifyMissingTranslation(String translationKey) {
if(!MISSING_KEYS.contains(translationKey)) {
if(SparkweaveApi.Client.LOG_MISSING_TRANSLATIONS) {
SparkweaveLogging.getLogger().warn("Missing translation for key '{}'", translationKey);
LOGGER.warn("Missing translation for key '{}'", translationKey);
}
MISSING_KEYS.add(translationKey);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package dev.upcraft.sparkweave.fabric.entrypoint;

import dev.upcraft.sparkweave.SparkweaveMod;
import dev.upcraft.sparkweave.api.annotation.CalledByReflection;
import dev.upcraft.sparkweave.api.entrypoint.MainEntryPoint;
import dev.upcraft.sparkweave.api.event.CommandEvents;
import dev.upcraft.sparkweave.api.platform.services.RegistryService;
import dev.upcraft.sparkweave.api.registry.block.BlockItemProvider;
import dev.upcraft.sparkweave.entrypoint.EntrypointHelper;
import dev.upcraft.sparkweave.logging.SparkweaveLogging;
import dev.upcraft.sparkweave.registry.SparkweaveCommandArgumentTypes;
import dev.upcraft.sparkweave.scheduler.ScheduledTaskQueue;
import net.fabricmc.api.ModInitializer;
Expand Down Expand Up @@ -51,6 +51,6 @@ public <T extends Item> T accept(Function<Item.Properties, T> factory, Supplier<

EntrypointHelper.fireEntrypoints(MainEntryPoint.class, MainEntryPoint::onInitialize);

SparkweaveLogging.getLogger().debug("System initialized!");
SparkweaveMod.onLoadComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import dev.upcraft.sparkweave.api.platform.services.RegistryService;
import dev.upcraft.sparkweave.api.registry.block.BlockItemProvider;
import dev.upcraft.sparkweave.entrypoint.EntrypointHelper;
import dev.upcraft.sparkweave.logging.SparkweaveLogging;
import dev.upcraft.sparkweave.registry.SparkweaveCommandArgumentTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -42,7 +41,7 @@ public Main(IEventBus bus) {
EntrypointHelper.fireEntrypoints(DedicatedServerEntryPoint.class, DedicatedServerEntryPoint::onInitializeServer);
}

SparkweaveLogging.getLogger().debug("System initialized!");
SparkweaveMod.onLoadComplete();
}

@SubscribeEvent
Expand Down

0 comments on commit bc34d25

Please sign in to comment.