mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-06 19:09:18 +01:00
Fix console channel logging errors constantly when not configured
This commit is contained in:
parent
731d8251ff
commit
739148ffd0
@ -24,6 +24,7 @@ public class ConsoleConfig {
|
|||||||
public String lineFormat = "[%log_time:'ccc HH:mm:ss zzz'%] [%log_level%] [%logger_name%] %message%";
|
public String lineFormat = "[%log_time:'ccc HH:mm:ss zzz'%] [%log_level%] [%logger_name%] %message%";
|
||||||
|
|
||||||
@Comment("The mode for the console output, available options are:\n"
|
@Comment("The mode for the console output, available options are:\n"
|
||||||
|
+ "- off: Turn off console appending\n"
|
||||||
+ "- ansi: A colored ansi code block\n"
|
+ "- ansi: A colored ansi code block\n"
|
||||||
+ "- log: A \"accesslog\" code block\n"
|
+ "- log: A \"accesslog\" code block\n"
|
||||||
+ "- diff: A \"diff\" code block highlighting warnings and errors with different colors\n"
|
+ "- diff: A \"diff\" code block highlighting warnings and errors with different colors\n"
|
||||||
@ -87,6 +88,9 @@ public class ConsoleConfig {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Comment("If command execution is enabled")
|
||||||
|
public boolean enabled = true;
|
||||||
|
|
||||||
@Comment("At least one condition has to match to allow execution")
|
@Comment("At least one condition has to match to allow execution")
|
||||||
public List<GameCommandFilterConfig> filters = new ArrayList<>();
|
public List<GameCommandFilterConfig> filters = new ArrayList<>();
|
||||||
|
|
||||||
@ -96,6 +100,7 @@ public class ConsoleConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum OutputMode {
|
public enum OutputMode {
|
||||||
|
OFF(null, null),
|
||||||
ANSI("```ansi\n", "```"),
|
ANSI("```ansi\n", "```"),
|
||||||
LOG("```accesslog\n", "```"),
|
LOG("```accesslog\n", "```"),
|
||||||
DIFF("```diff\n", "```"),
|
DIFF("```diff\n", "```"),
|
||||||
|
@ -4,12 +4,14 @@ import com.discordsrv.api.DiscordSRVApi;
|
|||||||
import com.discordsrv.api.discord.connection.details.DiscordGatewayIntent;
|
import com.discordsrv.api.discord.connection.details.DiscordGatewayIntent;
|
||||||
import com.discordsrv.common.DiscordSRV;
|
import com.discordsrv.common.DiscordSRV;
|
||||||
import com.discordsrv.common.config.main.ConsoleConfig;
|
import com.discordsrv.common.config.main.ConsoleConfig;
|
||||||
|
import com.discordsrv.common.config.main.generic.DestinationConfig;
|
||||||
import com.discordsrv.common.console.entry.LogEntry;
|
import com.discordsrv.common.console.entry.LogEntry;
|
||||||
import com.discordsrv.common.logging.LogAppender;
|
import com.discordsrv.common.logging.LogAppender;
|
||||||
import com.discordsrv.common.logging.LogLevel;
|
import com.discordsrv.common.logging.LogLevel;
|
||||||
import com.discordsrv.common.logging.NamedLogger;
|
import com.discordsrv.common.logging.NamedLogger;
|
||||||
import com.discordsrv.common.logging.backend.LoggingBackend;
|
import com.discordsrv.common.logging.backend.LoggingBackend;
|
||||||
import com.discordsrv.common.module.type.AbstractModule;
|
import com.discordsrv.common.module.type.AbstractModule;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -48,6 +50,16 @@ public class ConsoleModule extends AbstractModule<DiscordSRV> implements LogAppe
|
|||||||
|
|
||||||
List<ConsoleConfig> configs = discordSRV.config().console;
|
List<ConsoleConfig> configs = discordSRV.config().console;
|
||||||
for (ConsoleConfig config : configs) {
|
for (ConsoleConfig config : configs) {
|
||||||
|
DestinationConfig.Single destination = config.channel;
|
||||||
|
if (destination.channelId == 0L && StringUtils.isEmpty(destination.threadName)) {
|
||||||
|
logger().debug("Skipping a console handler due to lack of channel");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (config.appender.outputMode == ConsoleConfig.OutputMode.OFF && !config.commandExecution.enabled) {
|
||||||
|
logger().debug("Skipping console handler because output mode is OFF and command execution is disabled");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
handlers.add(new SingleConsoleHandler(discordSRV, logger(), config));
|
handlers.add(new SingleConsoleHandler(discordSRV, logger(), config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class SingleConsoleHandler {
|
|||||||
private final DiscordSRV discordSRV;
|
private final DiscordSRV discordSRV;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final ConsoleConfig config;
|
private final ConsoleConfig config;
|
||||||
private final Queue<LogEntry> queue = new LinkedBlockingQueue<>();
|
private final Queue<LogEntry> queue;
|
||||||
private Future<?> queueProcessingFuture;
|
private Future<?> queueProcessingFuture;
|
||||||
private boolean shutdown = false;
|
private boolean shutdown = false;
|
||||||
|
|
||||||
@ -61,6 +61,7 @@ public class SingleConsoleHandler {
|
|||||||
this.discordSRV = discordSRV;
|
this.discordSRV = discordSRV;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.queue = config.appender.outputMode != ConsoleConfig.OutputMode.OFF ? new LinkedBlockingQueue<>() : null;
|
||||||
this.messageCache = config.appender.useEditing ? new ArrayList<>() : null;
|
this.messageCache = config.appender.useEditing ? new ArrayList<>() : null;
|
||||||
|
|
||||||
timeQueueProcess();
|
timeQueueProcess();
|
||||||
@ -161,6 +162,10 @@ public class SingleConsoleHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void queue(LogEntry entry) {
|
public void queue(LogEntry entry) {
|
||||||
|
if (queue == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
queue.offer(entry);
|
queue.offer(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +192,9 @@ public class SingleConsoleHandler {
|
|||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (config.appender.outputMode == ConsoleConfig.OutputMode.OFF) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.queueProcessingFuture = discordSRV.scheduler().runLater(this::processQueue, 2, TimeUnit.SECONDS);
|
this.queueProcessingFuture = discordSRV.scheduler().runLater(this::processQueue, 2, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +298,8 @@ public class SingleConsoleHandler {
|
|||||||
)
|
)
|
||||||
.thenApply(channels -> {
|
.thenApply(channels -> {
|
||||||
if (channels.isEmpty()) {
|
if (channels.isEmpty()) {
|
||||||
throw new IllegalStateException("No channel");
|
// Nowhere to send to
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordGuildMessageChannel channel = channels.get(0);
|
DiscordGuildMessageChannel channel = channels.get(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user