mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 09:46:24 +00:00
Improve logging
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
@@ -17,7 +17,8 @@ public class AddonsCommand implements CommandTemplate {
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
sender.sendMessage("Installed Addons:");
|
||||
main.getAddons().forEach(
|
||||
addon -> sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor()));
|
||||
main.getAddons().forEach(addon -> {
|
||||
sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.commands.profiler.ProfileCommand;
|
||||
|
||||
|
||||
public final class CommandUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CommandUtil.class);
|
||||
public static void registerAll(CommandManager manager) throws MalformedCommandException {
|
||||
logger.info("Registering Terra commands...");
|
||||
manager.register("profile", ProfileCommand.class);
|
||||
manager.register("reload", ReloadCommand.class);
|
||||
manager.register("addons", AddonsCommand.class);
|
||||
manager.register("version", VersionCommand.class);
|
||||
manager.register("getblock", GetBlockCommand.class);
|
||||
manager.register("packs", PacksCommand.class);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PacksCommand implements CommandTemplate {
|
||||
public void execute(CommandSender sender) {
|
||||
CheckedRegistry<ConfigPack> registry = main.getConfigRegistry();
|
||||
|
||||
if(registry.entries().size() == 0) {
|
||||
if(registry.entries().isEmpty()) {
|
||||
LangUtil.send("command.packs.none", sender);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
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;
|
||||
@@ -12,15 +15,20 @@ import com.dfsek.terra.config.lang.LangUtil;
|
||||
usage = "/terra reload"
|
||||
)
|
||||
public class ReloadCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReloadCommand.class);
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
if(!main.reload()) {
|
||||
LangUtil.send("command.reload-error", sender);
|
||||
} else {
|
||||
logger.info("Reloading Terra...");
|
||||
if(main.reload()) {
|
||||
logger.info("Terra reloaded successfully.");
|
||||
LangUtil.send("command.reload", sender);
|
||||
} else {
|
||||
logger.warn("Terra failed to reload.");
|
||||
LangUtil.send("command.reload-error", sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
||||
|
||||
@Override
|
||||
public void load(TerraPlugin main) {
|
||||
logger.info("Loading config values");
|
||||
logger.info("Loading config values from config.yml");
|
||||
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) {
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.load(this, new YamlConfiguration(file, "config.yml"));
|
||||
@@ -88,11 +88,11 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
||||
logger.error("Failed to load config", e);
|
||||
}
|
||||
|
||||
if(isDebugCommands())
|
||||
if(debugCommands)
|
||||
logger.info("Debug commands enabled.");
|
||||
if(isDebugProfiler())
|
||||
if(debugProfiler)
|
||||
logger.info("Debug profiler enabled.");
|
||||
if(isDebugScript())
|
||||
if(debugScript)
|
||||
logger.info("Script debug blocks enabled.");
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class LoaderImpl implements Loader {
|
||||
*/
|
||||
@Override
|
||||
public LoaderImpl open(String directory, String extension) {
|
||||
if(streams.size() != 0) throw new IllegalStateException("Attempted to load new directory before closing existing InputStreams");
|
||||
if(!streams.isEmpty()) throw new IllegalStateException("Attempted to load new directory before closing existing InputStreams");
|
||||
load(directory, extension);
|
||||
return this;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public abstract class LoaderImpl implements Loader {
|
||||
try {
|
||||
input.close();
|
||||
} catch(IOException e) {
|
||||
logger.warn("Error occurred while loading", e);
|
||||
logger.error("Error occurred while loading", e);
|
||||
}
|
||||
});
|
||||
streams.clear();
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.dfsek.terra.config.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
@@ -14,25 +17,29 @@ import com.dfsek.terra.api.lang.Language;
|
||||
public final class LangUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LangUtil.class);
|
||||
|
||||
private static Language language;
|
||||
@Nullable
|
||||
private static Language LANGUAGE = null;
|
||||
|
||||
private LangUtil() { }
|
||||
|
||||
public static void load(String langID, TerraPlugin main) {
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
try {
|
||||
File file1 = new File(file, langID + ".yml");
|
||||
logger.info(file1.getAbsolutePath());
|
||||
language = new LanguageImpl(file1);
|
||||
LANGUAGE = new LanguageImpl(file1);
|
||||
logger.info("Loaded language {}", langID);
|
||||
} catch(IOException e) {
|
||||
logger.error("Unable to load language: {}.\nDouble-check your configuration before reporting this to Terra!", langID, e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Language getLanguage() {
|
||||
return language;
|
||||
return Objects.requireNonNull(LANGUAGE);
|
||||
}
|
||||
|
||||
public static void send(String messageID, CommandSender sender, String... args) {
|
||||
language.getMessage(messageID).send(sender, args);
|
||||
Objects.requireNonNull(LANGUAGE).getMessage(messageID).send(sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ public class MetaStringPreprocessor extends MetaPreprocessor<Meta> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public @NotNull <T> Result<T> process(AnnotatedType t, T c, ConfigLoader loader, Meta annotation) {
|
||||
if(String.class.equals(t.getType()) && c instanceof String) { // String is final so we use #equals
|
||||
String candidate = (String) c;
|
||||
if(String.class.equals(t.getType()) && c instanceof String candidate) { // String is final so we use #equals
|
||||
StringSubstitutor substitutor = new StringSubstitutor(key -> {
|
||||
Object meta = getMetaValue(key);
|
||||
if(!(meta instanceof String) && !(meta instanceof Number) && !(meta instanceof Character) && !(meta instanceof Boolean)) {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -13,6 +16,8 @@ import com.dfsek.terra.profiler.exception.MalformedStackException;
|
||||
|
||||
|
||||
public class ProfilerImpl implements Profiler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProfilerImpl.class);
|
||||
|
||||
private static final ThreadLocal<Stack<Frame>> THREAD_STACK = ThreadLocal.withInitial(Stack::new);
|
||||
private static final ThreadLocal<Map<String, List<Long>>> TIMINGS = ThreadLocal.withInitial(HashMap::new);
|
||||
private static final ThreadLocal<Boolean> SAFE = ThreadLocal.withInitial(() -> false);
|
||||
@@ -22,7 +27,8 @@ public class ProfilerImpl implements Profiler {
|
||||
private volatile boolean running = false;
|
||||
|
||||
public ProfilerImpl() {
|
||||
if(instantiated) throw new IllegalStateException("Only one instance of Profiler may exist!");
|
||||
if(instantiated)
|
||||
throw new IllegalStateException("Only one instance of Profiler may exist!");
|
||||
instantiated = true;
|
||||
}
|
||||
|
||||
@@ -45,14 +51,14 @@ public class ProfilerImpl implements Profiler {
|
||||
|
||||
Map<String, List<Long>> timingsMap = TIMINGS.get();
|
||||
|
||||
if(timingsMap.size() == 0) {
|
||||
if(timingsMap.isEmpty()) {
|
||||
synchronized(accessibleThreadMaps) {
|
||||
accessibleThreadMaps.add(timingsMap);
|
||||
}
|
||||
}
|
||||
|
||||
Frame top = stack.pop();
|
||||
if(stack.size() != 0 ? !top.getId().endsWith("." + frame) : !top.getId().equals(frame))
|
||||
if(!stack.isEmpty() ? !top.getId().endsWith("." + frame) : !top.getId().equals(frame))
|
||||
throw new MalformedStackException("Expected " + frame + ", found " + top);
|
||||
|
||||
List<Long> timings = timingsMap.computeIfAbsent(top.getId(), id -> new ArrayList<>());
|
||||
@@ -64,16 +70,19 @@ public class ProfilerImpl implements Profiler {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
logger.info("Starting Terra profiler");
|
||||
running = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
logger.info("Stopping Terra profiler");
|
||||
running = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
logger.info("Resetting Terra profiler");
|
||||
accessibleThreadMaps.forEach(Map::clear);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
|
||||
try {
|
||||
for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) {
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user