Fix logger timestamp not showing time
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
188eafa2ee
commit
94c126e32b
@ -46,8 +46,8 @@ public class HidekoBot
|
||||
standardInviteLink = standardInviteLink.replace("%userid%", botUserId);
|
||||
|
||||
// log the invite-link to console so noob users can just click on it.
|
||||
logger.log("Bot User ID: " + botUserId, 10);
|
||||
logger.log("Invite Link: " + standardInviteLink, 10);
|
||||
logger.log("Bot User ID: " + botUserId, 5);
|
||||
logger.log("Invite Link: " + standardInviteLink, 5);
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package wtf.beatrice.hidekobot.utils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Logger
|
||||
@ -11,8 +10,9 @@ 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");
|
||||
private final String format = "[%date% %time%] [%class%] %message%";
|
||||
private final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd");
|
||||
private final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
|
||||
|
||||
// when initializing a new logger, save variables in that instance
|
||||
@ -25,9 +25,11 @@ public class Logger
|
||||
public void log(String message)
|
||||
{
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String currentTime = formatter.format(now);
|
||||
String currentDate = dateFormatter.format(now);
|
||||
String currentTime = timeFormatter.format(now);
|
||||
System.out.println(format
|
||||
.replace("%date%", currentTime)
|
||||
.replace("%date%", currentDate)
|
||||
.replace("%time%", currentTime)
|
||||
.replace("%class%", className)
|
||||
.replace("%message%", message));
|
||||
}
|
||||
@ -35,13 +37,16 @@ public class Logger
|
||||
// log a message to console after delaying it (in seconds).
|
||||
public void log(String message, int delay)
|
||||
{
|
||||
// create a new scheduled executor with an anonymous runnable...
|
||||
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// log the message
|
||||
log(message);
|
||||
}
|
||||
//... after waiting X seconds.
|
||||
}, delay, TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user