mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-03 22:36:10 +00:00
Migrate logging to SLF4J
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
@@ -3,6 +3,8 @@ package com.dfsek.terra;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.File;
|
||||
@@ -16,7 +18,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
@@ -28,7 +29,6 @@ import com.dfsek.terra.api.lang.Language;
|
||||
import com.dfsek.terra.api.profiler.Profiler;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.mutable.MutableBoolean;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.commands.TerraCommandManager;
|
||||
@@ -40,7 +40,6 @@ import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.util.logging.DebugLogger;
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,9 +48,10 @@ import com.dfsek.terra.util.logging.DebugLogger;
|
||||
* Implementations must invoke {@link #load()} in their constructors.
|
||||
*/
|
||||
public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractTerraPlugin.class);
|
||||
|
||||
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
||||
private final EventManager eventManager = new EventManagerImpl(this);
|
||||
|
||||
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
||||
|
||||
private final CheckedRegistry<ConfigPack> checkedConfigRegistry = new CheckedRegistryImpl<>(configRegistry);
|
||||
@@ -66,19 +66,11 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(this);
|
||||
|
||||
private final Lazy<Logger> logger = Lazy.lazy(() -> createLogger());
|
||||
private final Lazy<DebugLogger> debugLogger = Lazy.lazy(() -> new DebugLogger(logger()));
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
loaders.register(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return logger.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginConfig getTerraConfig() {
|
||||
return config;
|
||||
@@ -99,11 +91,6 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
return addonRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getDebugLogger() {
|
||||
return debugLogger.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventManager getEventManager() {
|
||||
return eventManager;
|
||||
@@ -122,7 +109,7 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
}
|
||||
LOADED.set(true);
|
||||
|
||||
logger().info("Initializing Terra...");
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
getPlatformAddon().ifPresent(addonRegistry::register);
|
||||
|
||||
@@ -132,7 +119,7 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
FileUtils.copyInputStreamToFile(stream, configFile);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config.yml resource from jar", e);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,16 +130,17 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
if(config.dumpDefaultConfig()) {
|
||||
try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) {
|
||||
if(resourcesConfig == null) {
|
||||
logger().info("No resources config found. Skipping resource dumping.");
|
||||
logger.info("No resources config found. Skipping resource dumping.");
|
||||
return;
|
||||
}
|
||||
String resourceYaml = IOUtils.toString(resourcesConfig, StandardCharsets.UTF_8);
|
||||
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
|
||||
resources.forEach((dir, entries) -> entries.forEach(entry -> {
|
||||
String resourcePath = dir + "/" + entry;
|
||||
String resourcePath = String.format("%s/%s", dir, entry);
|
||||
File resource = new File(getDataFolder(), resourcePath);
|
||||
if(resource.exists()) return; // dont overwrite
|
||||
logger().info("Dumping resource " + resource.getAbsolutePath());
|
||||
if(resource.exists())
|
||||
return; // dont overwrite
|
||||
logger.info("Dumping resource {}...", resource.getAbsolutePath());
|
||||
try {
|
||||
resource.getParentFile().mkdirs();
|
||||
resource.createNewFile();
|
||||
@@ -167,14 +155,12 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
}
|
||||
}));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error while dumping resources...", e);
|
||||
}
|
||||
} else {
|
||||
getDebugLogger().info("Skipping resource dumping.");
|
||||
logger.info("Skipping resource dumping.");
|
||||
}
|
||||
|
||||
debugLogger.value().setDebug(config.isDebugLogging()); // enable debug logger if applicable
|
||||
|
||||
if(config.isDebugProfiler()) { // if debug.profiler is enabled, start profiling
|
||||
profiler.start();
|
||||
}
|
||||
@@ -184,20 +170,18 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
if(!addonRegistry.loadAll(getClass().getClassLoader())) { // load all addons
|
||||
throw new IllegalStateException("Failed to load addons. Please correct addon installations to continue.");
|
||||
}
|
||||
logger().info("Loaded addons.");
|
||||
logger.info("Loaded addons.");
|
||||
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
logger.error("Error registering commands", e);
|
||||
}
|
||||
|
||||
|
||||
logger().info("Finished initialization.");
|
||||
logger.info("Finished initialization.");
|
||||
}
|
||||
|
||||
protected abstract Logger createLogger();
|
||||
|
||||
protected Optional<TerraAddon> getPlatformAddon() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
@@ -12,6 +15,8 @@ import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class InternalAddon extends TerraAddon {
|
||||
private static final Logger logger = LoggerFactory.getLogger(InternalAddon.class);
|
||||
|
||||
private final AbstractTerraPlugin main;
|
||||
|
||||
public InternalAddon(AbstractTerraPlugin main) {
|
||||
@@ -24,9 +29,9 @@ public class InternalAddon extends TerraAddon {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, PlatformInitializationEvent.class)
|
||||
.then(event -> {
|
||||
main.logger().info("Loading config packs...");
|
||||
logger.info("Loading config packs...");
|
||||
main.getRawConfigRegistry().loadAll(main);
|
||||
main.logger().info("Loaded packs.");
|
||||
logger.info("Loaded packs.");
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.commands.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
@@ -11,6 +14,8 @@ import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
@Command
|
||||
@DebugCommand
|
||||
public class ProfileQueryCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProfileQueryCommand.class);
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@@ -18,7 +23,7 @@ public class ProfileQueryCommand implements CommandTemplate {
|
||||
public void execute(CommandSender sender) {
|
||||
StringBuilder data = new StringBuilder("Terra Profiler data dump: \n");
|
||||
main.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
|
||||
main.logger().info(data.toString());
|
||||
logger.info(data.toString());
|
||||
sender.sendMessage("Profiler data dumped to console.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -13,19 +15,20 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.time.Duration;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.config.PluginConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PluginConfigImpl.class);
|
||||
|
||||
@Value("debug.commands")
|
||||
@Default
|
||||
private boolean debugCommands = false;
|
||||
|
||||
@Value("debug.log")
|
||||
@Default
|
||||
private boolean debugLog = false;
|
||||
private boolean debugLog = false; // TODO: 2021-08-30 remove me
|
||||
|
||||
@Value("debug.profiler")
|
||||
@Default
|
||||
@@ -77,20 +80,20 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
||||
|
||||
@Override
|
||||
public void load(TerraPlugin main) {
|
||||
Logger logger = main.logger();
|
||||
logger.info("Loading config values");
|
||||
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) {
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.load(this, new YamlConfiguration(file, "config.yml"));
|
||||
} catch(ConfigException | IOException | UncheckedIOException e) {
|
||||
logger.severe("Failed to load config");
|
||||
e.printStackTrace();
|
||||
logger.error("Failed to load config", e);
|
||||
}
|
||||
|
||||
if(isDebugCommands()) logger.info("Debug commands enabled.");
|
||||
if(isDebugLogging()) logger.info("Debug logging enabled.");
|
||||
if(isDebugProfiler()) logger.info("Debug profiler enabled.");
|
||||
if(isDebugScript()) logger.info("Script debug blocks enabled.");
|
||||
if(isDebugCommands())
|
||||
logger.info("Debug commands enabled.");
|
||||
if(isDebugProfiler())
|
||||
logger.info("Debug profiler enabled.");
|
||||
if(isDebugScript())
|
||||
logger.info("Script debug blocks enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -14,6 +17,8 @@ import java.util.stream.Stream;
|
||||
* Load all {@code *.yml} files from a {@link java.nio.file.Path}.
|
||||
*/
|
||||
public class FolderLoader extends LoaderImpl {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FolderLoader.class);
|
||||
|
||||
private final Path path;
|
||||
|
||||
public FolderLoader(Path path) {
|
||||
@@ -34,11 +39,11 @@ public class FolderLoader extends LoaderImpl {
|
||||
String rel = newPath.toPath().relativize(file).toString();
|
||||
streams.put(rel, new FileInputStream(file.toFile()));
|
||||
} catch(FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Could not find file to load", e);
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error while loading files", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -15,6 +17,8 @@ import com.dfsek.terra.api.config.Loader;
|
||||
|
||||
|
||||
public abstract class LoaderImpl implements Loader {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoaderImpl.class);
|
||||
|
||||
protected final Map<String, InputStream> streams = new HashMap<>();
|
||||
|
||||
@Override
|
||||
@@ -51,7 +55,7 @@ public abstract class LoaderImpl implements Loader {
|
||||
try {
|
||||
input.close();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.warn("Error occurred while loading", e);
|
||||
}
|
||||
});
|
||||
streams.clear();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
@@ -8,6 +11,8 @@ import java.util.zip.ZipFile;
|
||||
|
||||
|
||||
public class ZIPLoader extends LoaderImpl {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZIPLoader.class);
|
||||
|
||||
private final ZipFile file;
|
||||
|
||||
public ZIPLoader(ZipFile file) {
|
||||
@@ -33,7 +38,7 @@ public class ZIPLoader extends LoaderImpl {
|
||||
String rel = entry.getName().substring(directory.length());
|
||||
streams.put(rel, file.getInputStream(entry));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error while loading file from zip", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
package com.dfsek.terra.config.lang;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.lang.Language;
|
||||
|
||||
|
||||
public final class LangUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LangUtil.class);
|
||||
|
||||
private static Language language;
|
||||
|
||||
public static void load(String langID, TerraPlugin main) {
|
||||
Logger logger = main.logger();
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
try {
|
||||
File file1 = new File(file, langID + ".yml");
|
||||
logger.info(file1.getAbsolutePath());
|
||||
language = new LanguageImpl(file1);
|
||||
logger.info("Loaded language " + langID);
|
||||
logger.info("Loaded language {}", langID);
|
||||
} catch(IOException e) {
|
||||
logger.severe("Unable to load language: " + langID);
|
||||
e.printStackTrace();
|
||||
logger.severe("Double-check your configuration before reporting this to Terra!");
|
||||
logger.error("Unable to load language: {}.\nDouble-check your configuration before reporting this to Terra!", langID, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
@@ -78,6 +80,8 @@ import com.dfsek.terra.registry.config.ConfigTypeRegistry;
|
||||
* Represents a Terra configuration pack.
|
||||
*/
|
||||
public class ConfigPackImpl implements ConfigPack {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigPackImpl.class);
|
||||
|
||||
private final ConfigPackTemplate template = new ConfigPackTemplate();
|
||||
|
||||
private final RegistryFactory registryFactory = new RegistryFactoryImpl();
|
||||
@@ -127,7 +131,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
logger.info("Loading config pack \"{}\"", template.getID());
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
@@ -138,7 +142,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
main.logger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\"");
|
||||
logger.error("Failed to load config pack from folder \"{}\"", folder.getAbsolutePath(), e);
|
||||
throw e;
|
||||
}
|
||||
toWorldConfig(new DummyWorld()); // Build now to catch any errors immediately.
|
||||
@@ -177,7 +181,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
logger.info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
load(l, main);
|
||||
|
||||
@@ -190,7 +194,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
main.logger().severe("Failed to load config pack from ZIP archive \"" + file.getName() + "\"");
|
||||
logger.error("Failed to load config pack from ZIP archive \"{}\"", file.getName());
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -281,16 +285,14 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
OpenRegistry<T> registry = new OpenRegistryImpl<>();
|
||||
selfLoader.registerLoader(c, registry);
|
||||
abstractConfigLoader.registerLoader(c, registry);
|
||||
main.getDebugLogger().info("Registered loader for registry of class " + ReflectionUtil.typeToString(c));
|
||||
logger.debug("Registered loader for registry of class {}", ReflectionUtil.typeToString(c));
|
||||
|
||||
if(type instanceof ParameterizedType) {
|
||||
ParameterizedType param = (ParameterizedType) type;
|
||||
if(type instanceof ParameterizedType param) {
|
||||
Type base = param.getRawType();
|
||||
if(base instanceof Class // should always be true but we'll check anyways
|
||||
&& Supplier.class.isAssignableFrom((Class<?>) base)) { // If it's a supplier
|
||||
Type supplied = param.getActualTypeArguments()[0]; // Grab the supplied type
|
||||
if(supplied instanceof ParameterizedType) {
|
||||
ParameterizedType suppliedParam = (ParameterizedType) supplied;
|
||||
if(supplied instanceof ParameterizedType suppliedParam) {
|
||||
Type suppliedBase = suppliedParam.getRawType();
|
||||
if(suppliedBase instanceof Class // should always be true but we'll check anyways
|
||||
&& ObjectTemplate.class.isAssignableFrom((Class<?>) suppliedBase)) {
|
||||
@@ -299,8 +301,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
(Registry<Supplier<ObjectTemplate<Supplier<ObjectTemplate<?>>>>>) registry);
|
||||
selfLoader.registerLoader(templateType, loader);
|
||||
abstractConfigLoader.registerLoader(templateType, loader);
|
||||
main.getDebugLogger().info(
|
||||
"Registered template loader for registry of class " + ReflectionUtil.typeToString(templateType));
|
||||
logger.debug("Registered template loader for registry of class {}", ReflectionUtil.typeToString(templateType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,13 +362,9 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
private void checkDeadEntries(TerraPlugin main) {
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft()).getDeadEntries()
|
||||
.forEach((id, value) -> main.getDebugLogger()
|
||||
.warning("Dead entry in '" +
|
||||
ReflectionUtil.typeToString(
|
||||
clazz) +
|
||||
"' registry: '" +
|
||||
id + "'")));
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft())
|
||||
.getDeadEntries()
|
||||
.forEach((id, value) -> logger.warn("Dead entry in '{}' registry: '{}'", ReflectionUtil.typeToString(clazz), id)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@@ -431,9 +428,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
main.logger().info(
|
||||
"Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " +
|
||||
(System.nanoTime() - start) / 1000000D + "ms.");
|
||||
logger.info("Loaded config pack \"{}\" v{} by {} in {}ms.",
|
||||
template.getID(), template.getVersion(), template.getAuthor(), (System.nanoTime() - start) / 1000000.0D);
|
||||
}
|
||||
|
||||
protected Map<Type, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> getRegistryMap() {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.dfsek.terra.event;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -21,6 +22,8 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FunctionalEventHandlerImpl.class);
|
||||
|
||||
private final Map<Type, List<EventContextImpl<?>>> contextMap = new HashMap<>();
|
||||
|
||||
private final TerraPlugin main;
|
||||
@@ -42,13 +45,10 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
||||
((EventContextImpl<Event>) context).handle(event);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
if(context.isFailThrough() && event instanceof FailThroughEvent) throw e; // Rethrow if it's fail-through.
|
||||
StringWriter writer = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
main.logger().warning("Exception occurred during event handling:");
|
||||
main.logger().warning(writer.toString());
|
||||
main.logger().warning(
|
||||
"Report this to the maintainers of " + context.getAddon().getName() + ", " + context.getAddon().getAuthor());
|
||||
if(context.isFailThrough() && event instanceof FailThroughEvent)
|
||||
throw e; // Rethrow if it's fail-through.
|
||||
// else warn
|
||||
logger.warn("Exception occurred during event handling. Report this to the maintainers of {}, {}", context.getAddon().getName(), context.getAddon().getAuthor(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.registry.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -10,6 +13,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
|
||||
public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigTypeRegistry.class);
|
||||
|
||||
private final BiConsumer<String, ConfigType<?, ?>> callback;
|
||||
|
||||
private final TerraPlugin main;
|
||||
@@ -23,8 +28,8 @@ public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
||||
@Override
|
||||
public boolean register(String identifier, Entry<ConfigType<?, ?>> value) {
|
||||
callback.accept(identifier, value.getValue());
|
||||
main.getDebugLogger().info("Registered config registry with ID " + identifier + " to type " +
|
||||
ReflectionUtil.typeToString(value.getValue().getTypeKey().getType()));
|
||||
logger.debug("Registered config registry with ID {} to type {}", identifier,
|
||||
ReflectionUtil.typeToString(value.getValue().getTypeKey().getType()));
|
||||
return super.register(identifier, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.registry.master;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -13,6 +15,7 @@ import com.dfsek.terra.addon.PreLoadAddon;
|
||||
import com.dfsek.terra.addon.exception.AddonLoadException;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.injection.Injector;
|
||||
import com.dfsek.terra.api.injection.exception.InjectionException;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.inject.InjectorImpl;
|
||||
@@ -20,6 +23,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
|
||||
public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(AddonRegistry.class);
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
public AddonRegistry(TerraPlugin main) {
|
||||
@@ -35,7 +40,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
public boolean register(String identifier, TerraAddon addon) {
|
||||
if(contains(identifier)) throw new IllegalArgumentException("Addon " + identifier + " is already registered.");
|
||||
addon.initialize();
|
||||
main.logger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor());
|
||||
logger.info("Loaded addon {} v{}, by {}", addon.getName(), addon.getVersion(), addon.getAuthor());
|
||||
return super.register(identifier, addon);
|
||||
}
|
||||
|
||||
@@ -52,6 +57,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
return loadAll(TerraPlugin.class.getClassLoader());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "NestedTryStatement", "ThrowCaughtLocally" })
|
||||
public boolean loadAll(ClassLoader parent) {
|
||||
InjectorImpl<TerraPlugin> pluginInjector = new InjectorImpl<>(main);
|
||||
pluginInjector.addExplicitTarget(TerraPlugin.class);
|
||||
@@ -64,7 +70,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
|
||||
try {
|
||||
for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) {
|
||||
main.logger().info("Loading Addon(s) from: " + jar.getName());
|
||||
logger.info("Loading Addon(s) from: " + jar.getName());
|
||||
for(Class<? extends TerraAddon> addonClass : AddonClassLoader.fetchAddonClasses(jar, parent)) {
|
||||
pool.add(new PreLoadAddon(addonClass, jar));
|
||||
}
|
||||
@@ -82,8 +88,9 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
if(!LogManager.getLogManager().addLogger(addonLogger)) {
|
||||
addonLogger = LogManager.getLogManager().getLogger(logPrefix);
|
||||
}
|
||||
|
||||
InjectorImpl<Logger> loggerInjector = new InjectorImpl<>(addonLogger);
|
||||
|
||||
// TODO: 2021-08-30 Remove logger injector entirely?
|
||||
Injector<Logger> loggerInjector = new InjectorImpl<>(addonLogger);
|
||||
loggerInjector.addExplicitTarget(Logger.class);
|
||||
|
||||
try {
|
||||
@@ -97,19 +104,24 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
pluginInjector.inject(loadedAddon);
|
||||
loggerInjector.inject(loadedAddon);
|
||||
} catch(InstantiationException | IllegalAccessException | InvocationTargetException | InjectionException e) {
|
||||
throw new AddonLoadException("Failed to load com.dfsek.terra.addon \" + " + addon.getId() + "\": ", e);
|
||||
throw new AddonLoadException(String.format("Failed to load addon \"%s\"", addon.getId()), e);
|
||||
}
|
||||
try {
|
||||
registerChecked(loadedAddon.getName(), loadedAddon);
|
||||
} catch(DuplicateEntryException e) {
|
||||
valid = false;
|
||||
main.logger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded.");
|
||||
main.logger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName());
|
||||
main.logger().severe("Duplicate addon class: " + addonClass.getCanonicalName());
|
||||
logger.error("""
|
||||
Duplicate addon ID; addon with ID {} is already loaded.
|
||||
Existing addon class: {}
|
||||
Duplicate addon class: {}
|
||||
""",
|
||||
loadedAddon.getName(),
|
||||
get(loadedAddon.getName()).getClass().getCanonicalName(),
|
||||
addonClass.getCanonicalName());
|
||||
}
|
||||
}
|
||||
} catch(AddonLoadException | IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Failed during addon loading", e);
|
||||
valid = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.dfsek.terra.registry.master;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -16,6 +18,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
* Class to hold config packs
|
||||
*/
|
||||
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigRegistry.class);
|
||||
|
||||
public void load(File folder, TerraPlugin main) throws ConfigException {
|
||||
ConfigPack pack = new ConfigPackImpl(folder, main);
|
||||
register(pack.getID(), pack);
|
||||
@@ -29,16 +33,16 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
try {
|
||||
load(dir, main);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config pack {}", dir.getName(), e);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra"))) {
|
||||
try {
|
||||
main.getDebugLogger().info("Loading ZIP archive: " + zip.getName());
|
||||
logger.info("Loading ZIP archive: " + zip.getName());
|
||||
load(new ZipFile(zip), main);
|
||||
} catch(IOException | ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config pack {}", zip.getName(), e);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.util.logging;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
|
||||
|
||||
public class DebugLogger implements Logger {
|
||||
private final Logger logger;
|
||||
private boolean debug = false;
|
||||
|
||||
public DebugLogger(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
if(debug) logger.info(message);
|
||||
}
|
||||
|
||||
public void warning(String message) {
|
||||
if(debug) logger.warning(message);
|
||||
}
|
||||
|
||||
public void severe(String message) {
|
||||
if(debug) logger.severe(message);
|
||||
}
|
||||
|
||||
public void stack(Throwable e) {
|
||||
if(debug) e.printStackTrace();
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.util.logging;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
|
||||
|
||||
public class JavaLogger implements Logger {
|
||||
private final java.util.logging.Logger logger;
|
||||
|
||||
public JavaLogger(java.util.logging.Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(String message) {
|
||||
logger.warning(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String message) {
|
||||
logger.severe(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user