refactor(logger): remove LoggerUtil and add simplelogger for tests
This commit is contained in:
parent
ef9384336a
commit
83b446e6fb
@ -13,6 +13,7 @@ cutin = "0.1.1-cad019e"
|
||||
[libraries]
|
||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j"}
|
||||
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j"}
|
||||
javacord = { module = "org.javacord:javacord", version.ref = "javacord"}
|
||||
discord4j = { module = "com.discord4j:discord4j-core", version.ref = "discord4j"}
|
||||
geantyref = { module = "io.leangen.geantyref:geantyref", version.ref = "geantyref"}
|
||||
|
@ -4,6 +4,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.cutin.MethodExecutor;
|
||||
import net.tomatentum.cutin.ProcessorMethodExecutor;
|
||||
@ -18,14 +19,13 @@ import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.interaction.ident.RootCommandIdentifier;
|
||||
import net.tomatentum.marinara.interaction.processor.AutocompleteInteractionProcessor;
|
||||
import net.tomatentum.marinara.interaction.processor.DirectInteractionProcessor;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
import net.tomatentum.marinara.util.ObjectAggregator;
|
||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
|
||||
public class Marinara {
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public static Marinara load(LibraryWrapper wrapper) {
|
||||
return new Marinara(wrapper);
|
||||
|
@ -3,9 +3,9 @@ package net.tomatentum.marinara.checks;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.cutin.method.ReflectedMethod;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
|
||||
public record AppliedCheck(
|
||||
Annotation annotation,
|
||||
@ -13,7 +13,7 @@ public record AppliedCheck(
|
||||
ReflectedMethod<CheckMethodIdentifier, CheckExecutionContext> postExec
|
||||
) {
|
||||
|
||||
private static Logger logger = LoggerUtil.getLogger(AppliedCheck.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(AppliedCheck.class);
|
||||
|
||||
public boolean pre(Object context) {
|
||||
logger.debug("Running InteractionCheck preExec {} with annotation {}", preExec(), annotation());
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.CommandChoices;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
|
||||
@ -14,7 +15,6 @@ import net.tomatentum.marinara.interaction.commands.choice.EnumChoices;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.interaction.ident.RootCommandIdentifier;
|
||||
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
|
||||
public class SlashCommandDefinition {
|
||||
|
||||
@ -30,7 +30,7 @@ public class SlashCommandDefinition {
|
||||
private RootCommandIdentifier rootIdentifier;
|
||||
private boolean isRootCommand;
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public SlashCommandDefinition(RootCommandIdentifier rootIdentifier) {
|
||||
this.entries = new HashSet<>();
|
||||
|
@ -91,8 +91,8 @@ public class InteractionIdentifier {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (parent() == null)
|
||||
return name();
|
||||
return "%s.%s".formatted(name(), parent().toString());
|
||||
return name() + " - " + type();
|
||||
return "%s:%s".formatted(name(), parent().toString());
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
@ -3,17 +3,17 @@ package net.tomatentum.marinara.interaction.processor;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.cutin.MethodProcessor;
|
||||
import net.tomatentum.cutin.container.MethodContainer;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||
|
||||
public abstract class InteractionMethodProcessor implements MethodProcessor<InteractionIdentifier, Object> {
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private IdentifierProvider provider;
|
||||
private Set<InteractionType> types;
|
||||
|
@ -4,18 +4,18 @@ import java.lang.reflect.Method;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.cutin.MethodParser;
|
||||
import net.tomatentum.cutin.util.ReflectionUtil;
|
||||
import net.tomatentum.marinara.interaction.annotation.Button;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
|
||||
public class ButtonParser implements MethodParser {
|
||||
|
||||
private Method method;
|
||||
private Consumer<String> consumer;
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public ButtonParser(Method method, Consumer<String> consumer) {
|
||||
this.method = method;
|
||||
|
@ -4,12 +4,17 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.leangen.geantyref.GenericTypeReflector;
|
||||
import net.tomatentum.cutin.MethodParser;
|
||||
import net.tomatentum.marinara.checks.InteractionCheck;
|
||||
|
||||
public class InteractionCheckClassParser implements MethodParser {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private Class<? extends InteractionCheck<?>> interactionCheckType;
|
||||
private Consumer<Type> annotationTypeConsumer;
|
||||
|
||||
@ -22,6 +27,7 @@ public class InteractionCheckClassParser implements MethodParser {
|
||||
public void parse() {
|
||||
ParameterizedType type = (ParameterizedType) GenericTypeReflector.getExactSuperType(interactionCheckType, InteractionCheck.class);
|
||||
Type typeParam = type.getActualTypeArguments()[0];
|
||||
logger.trace("Parsed InteractionCheck Annotation {}", typeParam);
|
||||
this.annotationTypeConsumer.accept(typeParam);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.cutin.MethodParser;
|
||||
import net.tomatentum.cutin.container.MethodContainer;
|
||||
@ -14,7 +15,6 @@ import net.tomatentum.marinara.checks.AppliedCheck;
|
||||
import net.tomatentum.marinara.checks.CheckExecutionContext;
|
||||
import net.tomatentum.marinara.checks.CheckMethodIdentifier;
|
||||
import net.tomatentum.marinara.checks.CheckMethodIdentifier.CheckMethodType;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
|
||||
public class InteractionCheckParser implements MethodParser {
|
||||
|
||||
@ -22,7 +22,7 @@ public class InteractionCheckParser implements MethodParser {
|
||||
private Method method;
|
||||
private Consumer<AppliedCheck> consumer;
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public InteractionCheckParser(Method method, Consumer<AppliedCheck> consumer, MethodContainer<CheckMethodIdentifier, CheckExecutionContext> checkContainer) {
|
||||
this.checkContainer = checkContainer;
|
||||
|
@ -4,6 +4,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.cutin.MethodParser;
|
||||
import net.tomatentum.cutin.util.ReflectionUtil;
|
||||
@ -13,14 +14,13 @@ import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
|
||||
public class SlashCommandParser implements MethodParser {
|
||||
|
||||
private Method method;
|
||||
private Consumer<SlashCommandIdentifier> consumer;
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public SlashCommandParser(Method method, Consumer<SlashCommandIdentifier> consumer) {
|
||||
this.method = method;
|
||||
|
@ -1,17 +0,0 @@
|
||||
package net.tomatentum.marinara.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.helpers.NOPLoggerFactory;
|
||||
|
||||
public class LoggerUtil {
|
||||
public static Logger getLogger(String name) {
|
||||
if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory)
|
||||
return new SimpleLogger(name);
|
||||
return LoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
public static Logger getLogger(Class<?> clazz) {
|
||||
return getLogger(clazz.getName());
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package net.tomatentum.marinara.util;
|
||||
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.event.Level;
|
||||
import org.slf4j.helpers.LegacyAbstractLogger;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
public class SimpleLogger extends LegacyAbstractLogger {
|
||||
|
||||
private String name;
|
||||
|
||||
public SimpleLogger(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFullyQualifiedCallerName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleNormalizedLoggingCall(Level level, Marker marker, String messagePattern, Object[] arguments,
|
||||
Throwable throwable) {
|
||||
String formatted = MessageFormatter.basicArrayFormat(messagePattern, arguments);
|
||||
System.out.println("[%s] %s => %s".formatted(level, this.name, formatted));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
|
||||
@ -12,7 +13,6 @@ import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptio
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.interaction.ident.RootCommandIdentifier;
|
||||
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
|
||||
public class CommandConverter<A extends Object, O extends Object, C extends Object> {
|
||||
|
||||
@ -20,7 +20,7 @@ public class CommandConverter<A extends Object, O extends Object, C extends Obje
|
||||
return new CommandConverter<>(spec);
|
||||
}
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private Spec<A, O, C> spec;
|
||||
|
||||
|
@ -5,9 +5,9 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
import net.tomatentum.marinara.util.ObjectAggregator;
|
||||
|
||||
public class CommandRegisterer<A extends Object> {
|
||||
@ -16,7 +16,7 @@ public class CommandRegisterer<A extends Object> {
|
||||
return new CommandRegisterer<A>(strategy, converter);
|
||||
}
|
||||
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private Strategy<A> strategy;
|
||||
private CommandConverter<A, ?, ?> converter;
|
||||
@ -29,13 +29,17 @@ public class CommandRegisterer<A extends Object> {
|
||||
public void register(SlashCommandDefinition[] slashDefs) {
|
||||
Set<ServerCommandList<A>> serverCommands = new ObjectAggregator<SlashCommandDefinition, Long, ServerCommandList<A>>(
|
||||
def -> Arrays.stream(def.serverIds()).boxed().toList(),
|
||||
(l, o) -> l.add(converter.convert(o)),
|
||||
(l, o) -> {
|
||||
logger.debug("Added {} for server ({}) registration.", o.rootIdentifier(), l.serverId());
|
||||
l.add(converter.convert(o));
|
||||
},
|
||||
ServerCommandList::new)
|
||||
.aggregate(Arrays.asList(slashDefs)).stream()
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<A> globalCommands = Arrays.stream(slashDefs)
|
||||
.filter(x -> x.serverIds().length <= 0)
|
||||
.peek(c -> logger.debug("Added {} for global registration.", c.rootIdentifier()))
|
||||
.map(converter::convert)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
|
@ -8,11 +8,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.leangen.geantyref.GenericTypeReflector;
|
||||
import net.tomatentum.cutin.util.ReflectionUtil;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
|
||||
public class IdentifierProvider {
|
||||
|
||||
@ -20,8 +20,9 @@ public class IdentifierProvider {
|
||||
return new IdentifierProvider(Arrays.asList(converter));
|
||||
}
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private Map<Class<?>, Converter<?>> converter;
|
||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||
|
||||
private IdentifierProvider(List<Converter<?>> converter) {
|
||||
this.converter = new HashMap<>();
|
||||
@ -47,7 +48,9 @@ public class IdentifierProvider {
|
||||
@SuppressWarnings("unchecked")
|
||||
Converter<Object> conv = (Converter<Object>) converter.get(type);
|
||||
|
||||
return conv.convert(context);
|
||||
InteractionIdentifier result = conv.convert(context);
|
||||
logger.trace("Converted {} to {} using {}", context, result, conv);
|
||||
return result;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
|
@ -17,6 +17,8 @@ dependencies {
|
||||
testImplementation(libs.discord4j)
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
testImplementation(libs.slf4j.simple)
|
||||
|
||||
implementation(libs.slf4j)
|
||||
implementation(libs.discord4j) {
|
||||
exclude(module="discord4j-voice")
|
||||
|
@ -10,7 +10,7 @@ import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
||||
import net.tomatentum.marinara.wrapper.ServerCommandList;
|
||||
|
||||
public class Discord4JRegistererStrategy implements CommandRegisterer.Strategy<ApplicationCommandRequest> {
|
||||
|
||||
|
||||
private ApplicationService appService;
|
||||
private long applicationId;
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
# SLF4J's SimpleLogger configuration file
|
||||
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
|
||||
|
||||
# Default logging detail level for all instances of SimpleLogger.
|
||||
# Must be one of ("trace", "debug", "info", "warn", or "error").
|
||||
# If not specified, defaults to "info".
|
||||
org.slf4j.simpleLogger.defaultLogLevel=trace
|
@ -16,6 +16,8 @@ dependencies {
|
||||
testImplementation(libs.mockito)
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
testImplementation(libs.slf4j.simple)
|
||||
|
||||
implementation(libs.slf4j)
|
||||
implementation(libs.javacord)
|
||||
implementation(libs.geantyref)
|
||||
|
@ -0,0 +1,7 @@
|
||||
# SLF4J's SimpleLogger configuration file
|
||||
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
|
||||
|
||||
# Default logging detail level for all instances of SimpleLogger.
|
||||
# Must be one of ("trace", "debug", "info", "warn", or "error").
|
||||
# If not specified, defaults to "info".
|
||||
org.slf4j.simpleLogger.defaultLogLevel=trace
|
Loading…
x
Reference in New Issue
Block a user