HidekoBot/src/main/java/wtf/beatrice/hidekobot/utils/Logger.java

32 lines
945 B
Java
Raw Normal View History

2022-08-25 22:13:39 +02:00
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));
}
}