From 3de0f3207482df9a913dafd589c01a1181a285c4 Mon Sep 17 00:00:00 2001 From: tueem Date: Thu, 19 Dec 2024 12:28:27 +0100 Subject: [PATCH 01/15] change to just javacord api dependency --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 593f827..de79cc7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,6 +9,6 @@ geantyref = "2.0.0" [libraries] junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } -log4j = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j"} +log4j = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j"} javacord = { module = "org.javacord:javacord", version.ref = "javacord"} geantyref = { module = "io.leangen.geantyref:geantyref", version.ref = "geantyref"} -- 2.45.2 From a17f5e826f42e55c3f6d10213867eff53002ec2d Mon Sep 17 00:00:00 2001 From: tueem Date: Thu, 19 Dec 2024 12:28:45 +0100 Subject: [PATCH 02/15] add LoggerUtil to decide which Logger to get --- .../tomatentum/marinara/util/LoggerUtil.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java diff --git a/lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java b/lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java new file mode 100644 index 0000000..99c57cd --- /dev/null +++ b/lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java @@ -0,0 +1,20 @@ +package net.tomatentum.marinara.util; + +import java.util.Properties; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.simple.SimpleLogger; +import org.apache.logging.log4j.util.PropertiesUtil; +import org.apache.logging.log4j.util.ProviderUtil; + +public class LoggerUtil { + public static Logger getLogger(String name) { + if (ProviderUtil.hasProviders()) { + return LogManager.getLogger(name); + }else + return new SimpleLogger(name, Level.DEBUG, true, false, true, true, "yyyy-MM-dd HH:mm:ss.SSSZ", null, + new PropertiesUtil(new Properties()), System.out); + } +} -- 2.45.2 From bf0022775d518273ef99d812f4cd9550ceb1c0ee Mon Sep 17 00:00:00 2001 From: tueem Date: Thu, 19 Dec 2024 13:30:36 +0100 Subject: [PATCH 03/15] add helper LoggerUtil method --- .../main/java/net/tomatentum/marinara/util/LoggerUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java b/lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java index 99c57cd..bf883db 100644 --- a/lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java +++ b/lib/src/main/java/net/tomatentum/marinara/util/LoggerUtil.java @@ -17,4 +17,8 @@ public class LoggerUtil { return new SimpleLogger(name, Level.DEBUG, true, false, true, true, "yyyy-MM-dd HH:mm:ss.SSSZ", null, new PropertiesUtil(new Properties()), System.out); } + + public static Logger getLogger(Class clazz) { + return getLogger(clazz.getName()); + } } -- 2.45.2 From 1ecbc563a63a70cea8656286b3f260c9eff22726 Mon Sep 17 00:00:00 2001 From: tueem Date: Thu, 19 Dec 2024 18:07:33 +0100 Subject: [PATCH 04/15] add Logging in InteractionRegistry --- .../registry/InteractionRegistry.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java index d1640d6..8bb8612 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java @@ -5,15 +5,19 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import org.apache.logging.log4j.Logger; + import net.tomatentum.marinara.Marinara; import net.tomatentum.marinara.interaction.InteractionHandler; import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition; import net.tomatentum.marinara.interaction.methods.SlashCommandInteractionMethod; +import net.tomatentum.marinara.util.LoggerUtil; import net.tomatentum.marinara.interaction.methods.InteractionMethod; public class InteractionRegistry { + private Logger logger = LoggerUtil.getLogger(getClass()); private List interactionMethods; private Marinara marinara; @@ -26,8 +30,11 @@ public class InteractionRegistry { public void addInteractions(InteractionHandler interactionHandler) { for (Method method : interactionHandler.getClass().getMethods()) { InteractionMethod iMethod = InteractionMethod.create(method, interactionHandler, marinara); - if (iMethod != null) + if (iMethod != null) { this.interactionMethods.add(iMethod); + logger.debug("Added {} method from {}", iMethod.getMethod().getName(), interactionHandler.getClass().getSimpleName()); + } + logger.info("Added all Interactions from {}", interactionHandler.getClass().getSimpleName()); } } @@ -46,16 +53,26 @@ public class InteractionRegistry { appDef.get().addExecutableCommand(def); else defs.add(new SlashCommandDefinition(def.applicationCommand()).addExecutableCommand(def)); + + logger.debug("Added Executable Command {}{}{} for registration", + def.applicationCommand().name(), + def.subCommandGroup().name().isBlank() ? "" : "." + def.subCommandGroup().name(), + def.subCommand().name().isBlank() ? "" : "." + def.subCommand().name() + ); }); - marinara.getWrapper().registerSlashCommands(defs.toArray(new SlashCommandDefinition[0])); + marinara.getWrapper().registerSlashCommands(defs.toArray(SlashCommandDefinition[]::new)); + logger.info("Registered all SlashCommands"); } public void handle(Object context) { + InteractionType type = marinara.getWrapper().getInteractionType(context.getClass()); + logger.debug("Received {} interaction ", context); interactionMethods.forEach((m) -> { - InteractionType type = marinara.getWrapper().getInteractionType(context.getClass()); - if (m.getType().equals(type) && m.canRun(context)) + if (m.getType().equals(type) && m.canRun(context)) { m.run(context); + logger.info("Running {} interaction using {}\ncontext: {}", type, m.getMethod().toString(), context.toString()); + } }); } } -- 2.45.2 From 3d19fae6b8070f9ddad4c0ba8fceaad334be5d14 Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 18:34:00 +0100 Subject: [PATCH 05/15] fix null issue in InteractionRegistry --- .../net/tomatentum/marinara/registry/InteractionRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java index 8bb8612..18e04b6 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java @@ -56,8 +56,8 @@ public class InteractionRegistry { logger.debug("Added Executable Command {}{}{} for registration", def.applicationCommand().name(), - def.subCommandGroup().name().isBlank() ? "" : "." + def.subCommandGroup().name(), - def.subCommand().name().isBlank() ? "" : "." + def.subCommand().name() + def.subCommandGroup() == null ? "" : "." + def.subCommandGroup().name(), + def.subCommand() == null ? "" : "." + def.subCommand().name() ); }); -- 2.45.2 From 76ab779ab2edd626fb8b7251288ad4ac9bc4d13c Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 18:36:51 +0100 Subject: [PATCH 06/15] fix position of Logging in InteractionRegistry --- .../net/tomatentum/marinara/registry/InteractionRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java index 18e04b6..12d31e7 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java @@ -34,8 +34,8 @@ public class InteractionRegistry { this.interactionMethods.add(iMethod); logger.debug("Added {} method from {}", iMethod.getMethod().getName(), interactionHandler.getClass().getSimpleName()); } - logger.info("Added all Interactions from {}", interactionHandler.getClass().getSimpleName()); } + logger.info("Added all Interactions from {}", interactionHandler.getClass().getSimpleName()); } public void registerCommands() { -- 2.45.2 From 7a40aebd6d621b0e9e467b114226f61593a46a32 Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 19:41:37 +0100 Subject: [PATCH 07/15] add Interactionmethod logging --- .../interaction/methods/InteractionMethod.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java index f9c5a1c..b4d7784 100644 --- a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java +++ b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java @@ -7,6 +7,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.logging.log4j.Logger; + import net.tomatentum.marinara.Marinara; import net.tomatentum.marinara.checks.AppliedCheck; import net.tomatentum.marinara.interaction.InteractionHandler; @@ -16,6 +18,7 @@ import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand; import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; import net.tomatentum.marinara.parser.AnnotationParser; import net.tomatentum.marinara.parser.InteractionCheckParser; +import net.tomatentum.marinara.util.LoggerUtil; public abstract class InteractionMethod { @@ -33,6 +36,8 @@ public abstract class InteractionMethod { protected List parsers; protected List appliedChecks; + private Logger logger = LoggerUtil.getLogger(getClass()); + protected InteractionMethod(Method method, InteractionHandler handler, Marinara marinara @@ -82,11 +87,14 @@ public abstract class InteractionMethod { List parameters = new ArrayList<>(); for (int i = 0; i < parameterCount; i++) { + Object parameter; if (i == 0) { - parameters.add(context); - continue; - } - parameters.add(getParameter(context, i-1)); + parameter = context; + }else + parameter = getParameter(context, i-1); + + logger.trace("Found parameter {}={} for {}", parameter.getClass().toString(), parameter, getMethod().getClass().getName() + "." + getMethod().getName()); + parameters.add(parameter); } return parameters.toArray(); } -- 2.45.2 From 6b86e9ff870eaf93ad503b9a5650348a4608a072 Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 19:41:49 +0100 Subject: [PATCH 08/15] add initialization Logging --- lib/src/main/java/net/tomatentum/marinara/Marinara.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/main/java/net/tomatentum/marinara/Marinara.java b/lib/src/main/java/net/tomatentum/marinara/Marinara.java index 0896858..c1be562 100644 --- a/lib/src/main/java/net/tomatentum/marinara/Marinara.java +++ b/lib/src/main/java/net/tomatentum/marinara/Marinara.java @@ -1,10 +1,15 @@ package net.tomatentum.marinara; +import org.apache.logging.log4j.Logger; + import net.tomatentum.marinara.registry.InteractionCheckRegistry; import net.tomatentum.marinara.registry.InteractionRegistry; +import net.tomatentum.marinara.util.LoggerUtil; import net.tomatentum.marinara.wrapper.LibraryWrapper; public class Marinara { + + private Logger logger = LoggerUtil.getLogger(getClass()); public static Marinara load(LibraryWrapper wrapper) { return new Marinara(wrapper); @@ -18,6 +23,7 @@ public class Marinara { this.wrapper = wrapper; this.registry = new InteractionRegistry(this); this.checkRegistry = new InteractionCheckRegistry(); + logger.info("Marinara loaded successfully!"); } public InteractionRegistry getRegistry() { -- 2.45.2 From 83ee4b1efa2b04a90cc6708cb40fc4a9e642e580 Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 20:04:53 +0100 Subject: [PATCH 09/15] add method name helper method --- .../java/net/tomatentum/marinara/util/ReflectionUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java b/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java index 2a65282..9446e8f 100644 --- a/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java +++ b/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java @@ -100,4 +100,8 @@ public final class ReflectionUtil { } return true; } + + public static String getFullMethodName(Method method) { + return method.getClass().getName() + "." + method.getName(); + } } -- 2.45.2 From b764972ebafc86e57e2fd26515ce79d7af7c4e42 Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 20:15:22 +0100 Subject: [PATCH 10/15] make use of new helper method in InteractionMethod --- .../marinara/interaction/methods/InteractionMethod.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java index b4d7784..437b2de 100644 --- a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java +++ b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java @@ -19,6 +19,7 @@ import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; import net.tomatentum.marinara.parser.AnnotationParser; import net.tomatentum.marinara.parser.InteractionCheckParser; import net.tomatentum.marinara.util.LoggerUtil; +import net.tomatentum.marinara.util.ReflectionUtil; public abstract class InteractionMethod { @@ -93,7 +94,7 @@ public abstract class InteractionMethod { }else parameter = getParameter(context, i-1); - logger.trace("Found parameter {}={} for {}", parameter.getClass().toString(), parameter, getMethod().getClass().getName() + "." + getMethod().getName()); + logger.trace("Found parameter {}={} for method {}", parameter.getClass().toString(), parameter, ReflectionUtil.getFullMethodName(method)); parameters.add(parameter); } return parameters.toArray(); -- 2.45.2 From 7249c99b6912e16da7d4d679068f4e423e3b9eae Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 20:38:04 +0100 Subject: [PATCH 11/15] add Logging to Parsers --- .../tomatentum/marinara/parser/ButtonParser.java | 7 +++++++ .../marinara/parser/InteractionCheckParser.java | 13 +++++++++++-- .../marinara/parser/SlashCommandParser.java | 8 ++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/parser/ButtonParser.java b/lib/src/main/java/net/tomatentum/marinara/parser/ButtonParser.java index 1b7dcbb..1e5bdb4 100644 --- a/lib/src/main/java/net/tomatentum/marinara/parser/ButtonParser.java +++ b/lib/src/main/java/net/tomatentum/marinara/parser/ButtonParser.java @@ -3,13 +3,19 @@ package net.tomatentum.marinara.parser; import java.lang.reflect.Method; import java.util.function.Consumer; +import org.apache.logging.log4j.Logger; + import net.tomatentum.marinara.interaction.annotation.Button; +import net.tomatentum.marinara.util.LoggerUtil; +import net.tomatentum.marinara.util.ReflectionUtil; public class ButtonParser implements AnnotationParser { private Method method; private Consumer consumer; + private Logger logger = LoggerUtil.getLogger(getClass()); + public ButtonParser(Method method, Consumer consumer) { this.method = method; this.consumer = consumer; @@ -18,6 +24,7 @@ public class ButtonParser implements AnnotationParser { @Override public void parse() { Button button = getMethod().getAnnotation(Button.class); + logger.trace("Parsed Button annotation {} for method {}", button.toString(), ReflectionUtil.getFullMethodName(method)); this.consumer.accept(button.value()); } diff --git a/lib/src/main/java/net/tomatentum/marinara/parser/InteractionCheckParser.java b/lib/src/main/java/net/tomatentum/marinara/parser/InteractionCheckParser.java index abba9e9..a397168 100644 --- a/lib/src/main/java/net/tomatentum/marinara/parser/InteractionCheckParser.java +++ b/lib/src/main/java/net/tomatentum/marinara/parser/InteractionCheckParser.java @@ -6,9 +6,13 @@ import java.util.Arrays; import java.util.Optional; import java.util.function.Consumer; +import org.apache.logging.log4j.Logger; + import net.tomatentum.marinara.checks.AppliedCheck; import net.tomatentum.marinara.checks.InteractionCheck; import net.tomatentum.marinara.registry.InteractionCheckRegistry; +import net.tomatentum.marinara.util.LoggerUtil; +import net.tomatentum.marinara.util.ReflectionUtil; public class InteractionCheckParser implements AnnotationParser { @@ -16,6 +20,8 @@ public class InteractionCheckParser implements AnnotationParser { private Method method; private Consumer consumer; + private Logger logger = LoggerUtil.getLogger(getClass()); + public InteractionCheckParser(Method method, Consumer consumer, InteractionCheckRegistry checkRegistry) { this.checkRegistry = checkRegistry; this.method = method; @@ -30,8 +36,11 @@ public class InteractionCheckParser implements AnnotationParser { private void convertAnnotation(Annotation annotation) { Optional> check = this.checkRegistry.getCheckFromAnnotation(annotation.annotationType()); - if (check.isPresent()) - consumer.accept(new AppliedCheck(check.get(), annotation)); + if (check.isPresent()) { + AppliedCheck appliedCheck = new AppliedCheck(check.get(), annotation); + logger.trace("Parsed InteractionCheck {} for annotation {} for method {}", check.getClass().getName(), annotation.toString(), ReflectionUtil.getFullMethodName(method)); + consumer.accept(appliedCheck); + } } @Override diff --git a/lib/src/main/java/net/tomatentum/marinara/parser/SlashCommandParser.java b/lib/src/main/java/net/tomatentum/marinara/parser/SlashCommandParser.java index 8997d9f..cf2a244 100644 --- a/lib/src/main/java/net/tomatentum/marinara/parser/SlashCommandParser.java +++ b/lib/src/main/java/net/tomatentum/marinara/parser/SlashCommandParser.java @@ -3,10 +3,13 @@ package net.tomatentum.marinara.parser; import java.lang.reflect.Method; import java.util.function.Consumer; +import org.apache.logging.log4j.Logger; + import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition; import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand; import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup; +import net.tomatentum.marinara.util.LoggerUtil; import net.tomatentum.marinara.util.ReflectionUtil; public class SlashCommandParser implements AnnotationParser { @@ -14,6 +17,8 @@ public class SlashCommandParser implements AnnotationParser { private Method method; private Consumer consumer; + private Logger logger = LoggerUtil.getLogger(getClass()); + public SlashCommandParser(Method method, Consumer consumer) { this.method = method; this.consumer = consumer; @@ -37,6 +42,9 @@ public class SlashCommandParser implements AnnotationParser { builder.setSubCommand(subCmd); } + ExecutableSlashCommandDefinition def = builder.build(); + + logger.trace("Parsed using SlashCommandParser for method {} with the result:\n{}", ReflectionUtil.getFullMethodName(method), def.toString()); consumer.accept(builder.build()); } -- 2.45.2 From 404f221ccf8538d6ef38cf96b5e4d2e0c4157033 Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 21:07:42 +0100 Subject: [PATCH 12/15] added Logging for InteractionChecks --- .../net/tomatentum/marinara/checks/AppliedCheck.java | 11 +++++++++-- .../marinara/registry/InteractionCheckRegistry.java | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java index 0383ac6..6f7ec53 100644 --- a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java +++ b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java @@ -5,9 +5,14 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; +import org.apache.logging.log4j.Logger; + +import net.tomatentum.marinara.util.LoggerUtil; import net.tomatentum.marinara.util.ReflectionUtil; public record AppliedCheck(InteractionCheck check, Annotation annotation) { + + private static Logger logger = LoggerUtil.getLogger(AppliedCheck.class); public boolean pre(Object context) { Method[] methods = Arrays.stream(check.getClass().getMethods()) @@ -17,9 +22,10 @@ public record AppliedCheck(InteractionCheck check, Annotation annotation) { Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.annotationType()); method.setAccessible(true); try { + logger.debug("Executing pre check {} with context {}", check.getClass().getName(), context.toString()); return (boolean) method.invoke(check, context, annotation); } catch (IllegalAccessException | InvocationTargetException | SecurityException e) { - e.printStackTrace(); + logger.fatal(e); return false; } } @@ -32,9 +38,10 @@ public record AppliedCheck(InteractionCheck check, Annotation annotation) { Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.annotationType()); method.setAccessible(true); try { + logger.debug("Executing pre check {} with context {}", check.getClass().getName(), context.toString()); method.invoke(check, context, annotation); } catch (IllegalAccessException | InvocationTargetException | SecurityException e) { - e.printStackTrace(); + logger.fatal(e); } } diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionCheckRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionCheckRegistry.java index 370419e..59f5220 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionCheckRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionCheckRegistry.java @@ -6,19 +6,25 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import org.apache.logging.log4j.Logger; + import io.leangen.geantyref.GenericTypeReflector; import net.tomatentum.marinara.checks.InteractionCheck; +import net.tomatentum.marinara.util.LoggerUtil; public class InteractionCheckRegistry { private List> checks; + private Logger logger = LoggerUtil.getLogger(getClass()); + public InteractionCheckRegistry() { this.checks = new ArrayList<>(); } public void addCheck(InteractionCheck check) { checks.add(check); + logger.info("Registered Check {}", check.getClass().getName()); } public Optional> getCheckFromAnnotation(Type annotation) { -- 2.45.2 From 74d55d81cad1f1e89b4b8fb3c30dc52418a3d5f0 Mon Sep 17 00:00:00 2001 From: Tueem Date: Thu, 19 Dec 2024 21:12:36 +0100 Subject: [PATCH 13/15] add remaining logging in Javacord wrapper and exceptions --- .../marinara/interaction/methods/InteractionMethod.java | 2 +- .../marinara/wrapper/javacord/JavacordWrapper.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java index 437b2de..06112ca 100644 --- a/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java +++ b/lib/src/main/java/net/tomatentum/marinara/interaction/methods/InteractionMethod.java @@ -73,7 +73,7 @@ public abstract class InteractionMethod { try { method.invoke(handler, getParameters(context)); }catch (IllegalAccessException | InvocationTargetException ex) { - throw new RuntimeException(ex); + logger.fatal(ex); } this.appliedChecks.forEach(x -> x.post(context)); diff --git a/wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/JavacordWrapper.java b/wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/JavacordWrapper.java index 98988df..ba540e6 100644 --- a/wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/JavacordWrapper.java +++ b/wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/JavacordWrapper.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.logging.log4j.Logger; import org.javacord.api.DiscordApi; import org.javacord.api.interaction.ApplicationCommandInteraction; import org.javacord.api.interaction.ButtonInteraction; @@ -25,15 +26,19 @@ import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptio import net.tomatentum.marinara.interaction.commands.annotation.SubCommand; import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup; import net.tomatentum.marinara.interaction.commands.option.SlashCommandOptionType; +import net.tomatentum.marinara.util.LoggerUtil; import net.tomatentum.marinara.wrapper.LibraryWrapper; public class JavacordWrapper extends LibraryWrapper { private DiscordApi api; + private Logger logger = LoggerUtil.getLogger(getClass()); + public JavacordWrapper(DiscordApi api) { this.api = api; api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction())); + logger.info("Javacord wrapper loaded!"); } @Override @@ -99,7 +104,7 @@ public class JavacordWrapper extends LibraryWrapper { }else builder.setSubCommand(TypeFactory.annotation(SubCommand.class, Map.of("name", options.getFirst().getName()))); } catch (AnnotationFormatException e) { - e.printStackTrace(); + logger.fatal(e); } return builder.build(); -- 2.45.2 From 628abb4239fb9ebb97d24bfa8388830fbd94bd3e Mon Sep 17 00:00:00 2001 From: Tueem Date: Fri, 20 Dec 2024 00:32:20 +0100 Subject: [PATCH 14/15] fix order and wording --- .../main/java/net/tomatentum/marinara/checks/AppliedCheck.java | 2 +- .../net/tomatentum/marinara/registry/InteractionRegistry.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java index 6f7ec53..3cd0b83 100644 --- a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java +++ b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java @@ -38,7 +38,7 @@ public record AppliedCheck(InteractionCheck check, Annotation annotation) { Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.annotationType()); method.setAccessible(true); try { - logger.debug("Executing pre check {} with context {}", check.getClass().getName(), context.toString()); + logger.debug("Executing post check {} with context {}", check.getClass().getName(), context.toString()); method.invoke(check, context, annotation); } catch (IllegalAccessException | InvocationTargetException | SecurityException e) { logger.fatal(e); diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java index 12d31e7..c771761 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java @@ -70,8 +70,8 @@ public class InteractionRegistry { logger.debug("Received {} interaction ", context); interactionMethods.forEach((m) -> { if (m.getType().equals(type) && m.canRun(context)) { - m.run(context); logger.info("Running {} interaction using {}\ncontext: {}", type, m.getMethod().toString(), context.toString()); + m.run(context); } }); } -- 2.45.2 From 3baf1eda9abdc4fcf8d5e396a14c7f1921d4d66c Mon Sep 17 00:00:00 2001 From: Tueem Date: Fri, 20 Dec 2024 00:44:48 +0100 Subject: [PATCH 15/15] log the result of an InteractionCheck --- .../java/net/tomatentum/marinara/checks/AppliedCheck.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java index 3cd0b83..6b4c487 100644 --- a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java +++ b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java @@ -23,7 +23,9 @@ public record AppliedCheck(InteractionCheck check, Annotation annotation) { method.setAccessible(true); try { logger.debug("Executing pre check {} with context {}", check.getClass().getName(), context.toString()); - return (boolean) method.invoke(check, context, annotation); + boolean result = (boolean) method.invoke(check, context, annotation); + logger.debug("Pre Check {} {} with context {}", check.getClass().getName(), result ? "succeeded" : "failed", context.toString()); + return result; } catch (IllegalAccessException | InvocationTargetException | SecurityException e) { logger.fatal(e); return false; -- 2.45.2