diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index 9a0d814..048bcc5 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -2,20 +2,23 @@ package wtf.beatrice.hidekobot; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; +import wtf.beatrice.hidekobot.utils.Logger; import javax.security.auth.login.LoginException; public class HidekoBot { + private static Logger logger = new Logger(HidekoBot.class); public static void main(String[] args) { try { - JDA jda = JDABuilder.createDefault("token").build(); + JDA jda = JDABuilder.createDefault("").build(); } catch (LoginException e) { - throw new RuntimeException(e); + logger.log(e.getMessage()); } } + } diff --git a/src/main/java/wtf/beatrice/hidekobot/utils/Logger.java b/src/main/java/wtf/beatrice/hidekobot/utils/Logger.java new file mode 100644 index 0000000..6872806 --- /dev/null +++ b/src/main/java/wtf/beatrice/hidekobot/utils/Logger.java @@ -0,0 +1,31 @@ +package wtf.beatrice.hidekobot.utils; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Logger +{ + + // objects that we need to have for a properly formatted message + private String className; + private final String format = "[%date%] [%class%] %message%"; + private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYY-MM-dd"); + + + // when initializing a new logger, save variables in that instance + public Logger(Class logClass) + { + className = logClass.getSimpleName(); + } + + // log a message to console, with our chosen format + public void log(String message) + { + LocalDateTime now = LocalDateTime.now(); + String currentTime = formatter.format(now); + System.out.println(format + .replace("%date%", currentTime) + .replace("%class%", className) + .replace("%message%", message)); + } +}