Add Logger class
This commit is contained in:
parent
5d34048ae6
commit
5d576b08eb
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
31
src/main/java/wtf/beatrice/hidekobot/utils/Logger.java
Normal file
31
src/main/java/wtf/beatrice/hidekobot/utils/Logger.java
Normal file
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user