Skip to content

Commit

Permalink
add log4j & use different log level on debug
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Jul 16, 2024
1 parent fc00a3f commit faf0891
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ dependencies {

// soft dependencies
compileOnly 'org.slf4j:slf4j-api:1.+'
compileOnly 'org.apache.logging.log4j:log4j-api:2.23.1'

compileOnly 'com.fasterxml.jackson.core:jackson-databind:2.+'
compileOnly 'antlr:antlr:2.7.7'
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/comroid/api/func/util/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.experimental.FieldDefaults;
import lombok.experimental.NonFinal;
import lombok.experimental.SuperBuilder;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.IMentionable;
Expand All @@ -27,6 +28,7 @@
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.TriState;
import org.apache.logging.log4j.Level;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
Expand All @@ -52,7 +54,6 @@
import org.comroid.api.func.Specifiable;
import org.comroid.api.func.ext.Wrap;
import org.comroid.api.info.Constraint;
import org.comroid.api.info.Log;
import org.comroid.api.java.Activator;
import org.comroid.api.java.ReflectionHelper;
import org.comroid.api.java.StackTraceUtils;
Expand Down Expand Up @@ -89,7 +90,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -99,6 +99,7 @@
import static java.util.stream.Stream.of;
import static java.util.stream.Stream.*;
import static net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer.*;
import static org.comroid.api.func.util.Debug.*;
import static org.comroid.api.func.util.Streams.*;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -316,8 +317,8 @@ class Usage {
Node.Callable baseNode = null;
@NonFinal
Node.Callable node;
@NonFinal
int callIndex;
@NonFinal @lombok.Builder.Default
int callIndex = 0;

public void advanceFull() {
// reset if necessary
Expand All @@ -343,6 +344,7 @@ public void advanceFull() {
}

@Value
@Log4j2
@NonFinal
@ToString(of = { "id" })
class Manager extends Container.Base implements Info, PermissionChecker {
Expand Down Expand Up @@ -468,7 +470,7 @@ public final Stream<AutoFillOption> autoComplete(Usage usage, String argName, @N
})
.map(str -> new AutoFillOption(str, str));
} catch (Throwable e) {
Log.at(Level.WARNING, "An error ocurred during command execution", e);
log.log(isDebug() ? Level.WARN : Level.DEBUG, "An error ocurred during command autocompletion", e);
return Stream.of(usage.source.handleThrowable(e))
.map(String::valueOf)
.map(str -> new AutoFillOption(str, ""));
Expand Down Expand Up @@ -589,7 +591,7 @@ public final boolean userHasPermission(Usage usage, Object key) {
} catch (Error err) {
response = err.response == null ? usage.source.handleThrowable(err) : err.response;
} catch (Throwable e) {
Log.at(Level.FINE, "An error ocurred during command execution", e);
log.log(isDebug() ? Level.ERROR : Level.DEBUG, "An error ocurred during command execution", e);
response = usage.source.handleThrowable(e);
}
if (response != null)
Expand Down

0 comments on commit faf0891

Please sign in to comment.