added Logging for InteractionChecks
This commit is contained in:
		| @@ -5,10 +5,15 @@ 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()) | ||||
|             .filter(x -> x.getName().equals("preExec")) | ||||
| @@ -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); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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<InteractionCheck<?>> 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<InteractionCheck<?>> getCheckFromAnnotation(Type annotation) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user