Changed to new logging, static implementation for now which is not ideal, but it's not worth spending the time to fix it right now
This commit is contained in:
@@ -2,11 +2,13 @@ package com.alttd.util;
|
||||
|
||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||
import net.dv8tion.jda.api.utils.FileUpload;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -28,7 +30,7 @@ public class ExcelWriter {
|
||||
|
||||
public synchronized void addRow(String... data) {
|
||||
if (done) {
|
||||
Logger.warning("Tried to write to finished excel file");
|
||||
Logger.altitudeLogs.warning("Tried to write to finished excel file");
|
||||
return;
|
||||
}
|
||||
Row row = sheet.createRow(currentRow++);
|
||||
|
||||
@@ -1,84 +1,32 @@
|
||||
package com.alttd.util;
|
||||
|
||||
import com.alttd.AltitudeBot;
|
||||
import com.alttd.AltitudeLogs;
|
||||
import com.alttd.LogLevel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Logger { //TODO make this log to a file
|
||||
|
||||
private static final java.util.logging.Logger info;
|
||||
private static final java.util.logging.Logger error;
|
||||
private static final java.util.logging.Logger sql;
|
||||
|
||||
public class Logger {
|
||||
public static AltitudeLogs altitudeLogs;
|
||||
static {
|
||||
File logDir = new File(new File(AltitudeBot.getInstance().getDataFolder()).getParent() + File.separator + "logs");
|
||||
if (!logDir.exists())
|
||||
{
|
||||
if (!logDir.mkdir()) {
|
||||
Logger.info("UNABLE TO CREATE LOGGING DIRECTORY");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
info = java.util.logging.Logger.getLogger("info");
|
||||
error = java.util.logging.Logger.getLogger("error");
|
||||
sql = java.util.logging.Logger.getLogger("sql");
|
||||
info.setLevel(Level.ALL);
|
||||
error.setLevel(Level.ALL);
|
||||
sql.setLevel(Level.ALL);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd");
|
||||
Date date = new Date();
|
||||
String formattedTime = dateFormat.format(date.getTime());
|
||||
|
||||
Logger.altitudeLogs = new AltitudeLogs().setTimeFormat("[HH:mm:ss] ");
|
||||
try {
|
||||
info.addHandler(new FileHandler(logDir.getAbsolutePath() + File.separator +
|
||||
formattedTime + "info.log"));
|
||||
error.addHandler(new FileHandler(logDir.getAbsolutePath() + File.separator +
|
||||
formattedTime + "error.log"));
|
||||
sql.addHandler(new FileHandler(logDir.getAbsolutePath() + File.separator +
|
||||
formattedTime + "sql.log"));
|
||||
Logger.altitudeLogs
|
||||
.setLogPath(new File(AltitudeBot.getInstance().getDataFolder()).getParent() + File.separator + "logs")
|
||||
.setLogName("debug.log", LogLevel.DEBUG)
|
||||
.setLogName("info.log", LogLevel.INFO)
|
||||
.setLogName("warning.log", LogLevel.WARNING)
|
||||
.setLogName("error.log", LogLevel.ERROR)
|
||||
.setLogDateFormat("yyyy-MM-dd");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
Logger.altitudeLogs.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void info(String message, String... replacements) {
|
||||
message = replace(message, replacements);
|
||||
info.info(message);
|
||||
}
|
||||
|
||||
public static void warning(String message, String... replacements) {
|
||||
message = replace(message, replacements);
|
||||
error.warning(message);
|
||||
}
|
||||
|
||||
public static void severe(String message, String... replacements) {
|
||||
message = replace(message, replacements);
|
||||
error.severe(message);
|
||||
}
|
||||
|
||||
public static void sql(String message) {
|
||||
sql.info(message);
|
||||
}
|
||||
|
||||
public static void sql(SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
sql.info("SQLState: " + exception.getSQLState() + "\n");
|
||||
sql.severe("Error:\n" + exception.getMessage());
|
||||
}
|
||||
|
||||
public static void exception(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
error.severe("Error:\n" + exception.getMessage());
|
||||
Logger.altitudeLogs.warning(message);
|
||||
}
|
||||
|
||||
private static String replace(String message, String... replacements) {
|
||||
@@ -90,4 +38,7 @@ public class Logger { //TODO make this log to a file
|
||||
return message;
|
||||
}
|
||||
|
||||
public static void setDebugActive(boolean debug) {
|
||||
Logger.altitudeLogs.setLogLevelActive(LogLevel.DEBUG, debug);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.alttd.commandManager.CommandManager;
|
||||
import com.alttd.commandManager.ScopeInfo;
|
||||
import com.alttd.commandManager.SubOption;
|
||||
import com.alttd.config.MessagesConfig;
|
||||
import com.alttd.config.SettingsConfig;
|
||||
import com.alttd.templates.Parser;
|
||||
import com.alttd.templates.Template;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
@@ -34,12 +33,12 @@ public class Util {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void ignoreSuccess(Object o) {
|
||||
public static void ignoreSuccess(Object ignoredO) {
|
||||
// IDK I thought this looked nicer in the .queue call
|
||||
}
|
||||
|
||||
public static void handleFailure(Throwable failure) {
|
||||
Logger.severe(failure.getMessage());
|
||||
Logger.altitudeLogs.error(failure.getMessage());
|
||||
}
|
||||
|
||||
public static MessageEmbed guildOnlyCommand(String commandName) {
|
||||
@@ -108,8 +107,7 @@ public class Util {
|
||||
for (ScopeInfo info : commandManager.getActiveLocations(commandName)) {
|
||||
switch (info.getScope()) {
|
||||
case GLOBAL -> {
|
||||
if (SettingsConfig.DEBUG)
|
||||
Logger.info("Loading command [" + commandName + "] on global.");
|
||||
Logger.altitudeLogs.debug("Loading command [" + commandName + "] on global.");
|
||||
jda.upsertCommand(commandData).queue();
|
||||
// jda.updateCommands().addCommands(commandData).queue();
|
||||
}
|
||||
@@ -117,7 +115,7 @@ public class Util {
|
||||
Guild guildById = jda.getGuildById(info.getId());
|
||||
if (guildById == null)
|
||||
{
|
||||
Logger.warning("Tried to add command % to invalid guild %.", commandName, String.valueOf(info.getId()));
|
||||
Logger.altitudeLogs.warning("Tried to add command " + commandName + " to invalid guild " + info.getId());
|
||||
continue;
|
||||
}
|
||||
registerCommand(guildById, commandData, commandName);
|
||||
@@ -127,15 +125,13 @@ public class Util {
|
||||
}
|
||||
|
||||
public static void registerCommand(Guild guild, CommandData commandData, String commandName) {
|
||||
if (SettingsConfig.DEBUG)
|
||||
Logger.info("Loading command [" + commandName + "] on guild [" + guild.getName() + "].");
|
||||
Logger.altitudeLogs.debug("Loading command [" + commandName + "] on guild [" + guild.getName() + "].");
|
||||
// guild.upsertCommand(commandData).queue();
|
||||
guild.upsertCommand(commandData).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||
}
|
||||
|
||||
public static void deleteCommand(Guild guild, long id, String commandName) {
|
||||
if (SettingsConfig.DEBUG)
|
||||
Logger.info("Deleting command [" + commandName + "] on guild [" + guild.getName() + "].");
|
||||
Logger.altitudeLogs.debug("Deleting command [" + commandName + "] on guild [" + guild.getName() + "].");
|
||||
guild.deleteCommandById(id).queue();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user