feat: print stack traces using LoggerUtilities
refactor: use the `console` in Main to access `reader` which can then `printAbove()`
This commit is contained in:
@@ -43,6 +43,7 @@ public class Main {
|
||||
|
||||
private static int backupFailTimes = 0;
|
||||
|
||||
public static ConsolePlugin console;
|
||||
public static DatabasePlugin database;
|
||||
private static DiscordPlugin discord;
|
||||
|
||||
@@ -130,7 +131,7 @@ public class Main {
|
||||
}
|
||||
|
||||
// initialize plugins
|
||||
new ConsolePlugin();
|
||||
console = new ConsolePlugin();
|
||||
LoggerPlugin.init();
|
||||
if (config.database.enabled) database = new DatabasePlugin(config);
|
||||
if (config.discord.enabled) discord = new DiscordPlugin(config);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.chayapak1.chomens_bot.util;
|
||||
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.Main;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class LoggerUtilities {
|
||||
}
|
||||
|
||||
public static void log (String message) { log(null, message, true, true); }
|
||||
public static void log (Component message) { log(null, ComponentUtilities.stringifyAnsi(message)); }
|
||||
public static void log (Component message) { log(null, message); }
|
||||
public static void log (Bot bot, Component message) { log(bot, ComponentUtilities.stringifyAnsi(message)); }
|
||||
public static void log (Bot bot, String message) { log(bot, message, true, true); }
|
||||
public static void log (Bot bot, String message, boolean logToFile, boolean logToConsole) {
|
||||
@@ -60,30 +61,29 @@ public class LoggerUtilities {
|
||||
}
|
||||
|
||||
public static void info (String message) { info(null, message); }
|
||||
public static void info (Component message) { info(null, ComponentUtilities.stringifyAnsi(message)); }
|
||||
public static void info (Component message) { info(null, message); }
|
||||
public static void info (Bot bot, Component message) { info(bot, ComponentUtilities.stringifyAnsi(message)); }
|
||||
public static void info (Bot bot, String message) {
|
||||
final String component = prefix(bot, Component.text("Info").color(NamedTextColor.GREEN), message);
|
||||
|
||||
if (bot != null) bot.console.reader.printAbove(component);
|
||||
else System.out.println(component);
|
||||
Main.console.reader.printAbove(component);
|
||||
}
|
||||
|
||||
public static void error (String message) { error(null, message); }
|
||||
public static void error (Component message) { error(null, ComponentUtilities.stringifyAnsi(message)); }
|
||||
public static void error (Component message) { error(null, message); }
|
||||
public static void error (Throwable throwable) { error(null, throwable); }
|
||||
public static void error (Bot bot, Component message) { error(bot, ComponentUtilities.stringifyAnsi(message)); }
|
||||
public static void error (Bot bot, Throwable throwable) { error(bot, ExceptionUtilities.getStacktrace(throwable)); }
|
||||
public static void error (Bot bot, String message) {
|
||||
final String component = prefix(bot, Component.text("Error").color(NamedTextColor.RED), message);
|
||||
|
||||
if (bot != null) bot.console.reader.printAbove(component);
|
||||
else System.err.println(component);
|
||||
Main.console.reader.printAbove(component);
|
||||
}
|
||||
|
||||
public static void custom (Component prefix, Component message) { custom(null, prefix, message); }
|
||||
public static void custom (Bot bot, Component prefix, Component _message) {
|
||||
final String message = prefix(bot, prefix, ComponentUtilities.stringifyAnsi(_message));
|
||||
|
||||
if (bot != null) bot.console.reader.printAbove(message);
|
||||
else System.out.println(message);
|
||||
Main.console.reader.printAbove(message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user