Added the initial of a simple logger, might switch to log4j or whatever its called.

This commit is contained in:
Tyler Jaacks
2025-02-24 17:32:38 -06:00
parent bf01df020d
commit bf656ad565
6 changed files with 247 additions and 1 deletions

View File

@@ -10,6 +10,8 @@ repositories {
}
dependencies {
implementation("net.dv8tion:JDA:5.3.0")
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

View File

@@ -0,0 +1,101 @@
package com.windurango;
public class BotProperties {
private static String BOT_NAME;
private static String BOT_VERSION;
private static String BOT_AUTHOR;
private static String BOT_TOKEN;
private static String BOT_SECRET;
private static String BOT_PREFIX;
private static String[] BOT_INTENTS;
private static String[] BOT_LOADABLE_MODULES;
private static String[] BOT_MESSAGE_LISTENERS;
private BotProperties() {
}
public BotProperties getInstance() {
return new BotProperties();
}
public static String getBotName() {
return BOT_NAME;
}
public static void setBotName(String botName) {
BOT_NAME = botName;
}
public static String getBotVersion() {
return BOT_VERSION;
}
public static void setBotVersion(String botVersion) {
BOT_VERSION = botVersion;
}
public static String getBotAuthor() {
return BOT_AUTHOR;
}
public static void setBotAuthor(String botAuthor) {
BOT_AUTHOR = botAuthor;
}
public static String getBotToken() {
return BOT_TOKEN;
}
public static void setBotToken(String botToken) {
BOT_TOKEN = botToken;
}
public static String getBotSecret() {
return BOT_SECRET;
}
public static void setBotSecret(String botSecret) {
BOT_SECRET = botSecret;
}
public static String getBotPrefix() {
return BOT_PREFIX;
}
public static void setBotPrefix(String botPrefix) {
BOT_PREFIX = botPrefix;
}
public static String[] getBotIntents() {
return BOT_INTENTS;
}
public static void setBotIntents(String[] botIntents) {
BOT_INTENTS = botIntents;
}
public static String[] getBotLoadableModules() {
return BOT_LOADABLE_MODULES;
}
public static void setBotLoadableModules(String[] botLoadableModules) {
BOT_LOADABLE_MODULES = botLoadableModules;
}
public static String[] getBotMessageListeners() {
return BOT_MESSAGE_LISTENERS;
}
public static void setBotMessageListeners(String[] botMessageListeners) {
BOT_MESSAGE_LISTENERS = botMessageListeners;
}
// TODO: Load properties from a configuration file.
public static void loadProperties() {
}
}

View File

@@ -1,7 +1,26 @@
package com.windurango;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.requests.GatewayIntent;
import java.util.Collection;
import java.util.EnumSet;
public class Main {
private static final Collection<GatewayIntent> intents = EnumSet.of(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS);
// TODO: Load these properties from a configuration file
public static final String PREFIX = "!";
public static final String BOT_NAME = "Windurango";
public static final String BOT_TOKEN = "";
public static final String BOT_VERSION = "0.0.1";
public static final String BOT_AUTHOR = "Windurango Team";
public static final String
public static void main(String[] args) {
System.out.println("Hello, World!");
JDABuilder
.create(BOT_TOKEN, intents)
.addEventListeners(new MessageListener())
.build();
}
}

View File

@@ -0,0 +1,11 @@
package com.windurango.logging;
public enum LogLevel {
INFO,
DEBUG,
WARNING,
ERROR,
CRITICAL,
ALL,
NONE
}

View File

@@ -0,0 +1,51 @@
package com.windurango.logging;
public class LogMessage {
private String message;
private LogLevel logLevel;
private String timestamp;
private Class<?> source;
public LogMessage() {
}
public LogMessage(String message, LogLevel logLevel, String timestamp, Class<?> source) {
this.message = message;
this.logLevel = logLevel;
this.timestamp = timestamp;
this.source = source;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public LogLevel getLogLevel() {
return logLevel;
}
public void setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public Class<?> getSource() {
return source;
}
public void setSource(Class<?> source) {
this.source = source;
}
}

View File

@@ -0,0 +1,62 @@
package com.windurango.logging;
import java.util.ArrayList;
import java.util.List;
/**
* A simple generics based singleton logger class.
*/
public class Logger<T> {
private static Logger<?> instance;
private static LogLevel logLevel;
List<LogMessage> logs = new ArrayList<>();
private Logger() {
logLevel = LogLevel.INFO;
}
@SuppressWarnings({"unchecked"})
public static synchronized <T> Logger<T> getInstance() {
if (instance == null) instance = new Logger<>();
return (Logger<T>) instance;
}
public void logInfo(String message) {
LogMessage logMessage = new LogMessage();
logMessage.setLogLevel(logLevel);
logMessage.setMessage(message);
logMessage.setTimestamp(String.valueOf(System.currentTimeMillis()));
// TODO: Get the class of this Logger object based on generics.
logs.add(logMessage);
}
public void logWarning() {
}
public void logError() {
}
public void logCritical() {
}
public void logDebug() {
}
public static LogLevel getLogLevel() {
return logLevel;
}
public static void setLogLevel(LogLevel logLevel) {
Logger.logLevel = logLevel;
}
}