Switch to using System.Logger instead of raw outputs
This commit is contained in:
parent
60f20b9549
commit
eb64994b5a
2 changed files with 12 additions and 8 deletions
|
@ -22,12 +22,14 @@ import org.apache.commons.cli.DefaultParser;
|
||||||
import org.apache.commons.cli.ParseException;
|
import org.apache.commons.cli.ParseException;
|
||||||
|
|
||||||
import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage;
|
import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage;
|
||||||
|
import static java.lang.System.Logger.Level;
|
||||||
|
|
||||||
// This file contains the main function and other utility function necessary for interpreting the terminal arguments.
|
// This file contains the main function and other utility function necessary for interpreting the terminal arguments.
|
||||||
// See README.md and LICENSE.md for license information
|
// See README.md and LICENSE.md for license information
|
||||||
// Author: Jonas Tobias Hopusch (@jotoho)
|
// Author: Jonas Tobias Hopusch (@jotoho)
|
||||||
|
|
||||||
public final class Main {
|
public final class Main {
|
||||||
|
private static final System.Logger logger = System.getLogger("main");
|
||||||
|
|
||||||
private static void printVersionInformation() {
|
private static void printVersionInformation() {
|
||||||
final var thisPackage = Main.class.getPackage();
|
final var thisPackage = Main.class.getPackage();
|
||||||
|
@ -47,8 +49,8 @@ public final class Main {
|
||||||
|
|
||||||
private static void printHelpInformation() {
|
private static void printHelpInformation() {
|
||||||
switch (applicationOutputLanguage) {
|
switch (applicationOutputLanguage) {
|
||||||
case GlobalConf.langGerman -> System.out.println("Hilfe kommt noch. (Nicht implementiert)");
|
case GlobalConf.langGerman -> logger.log(Level.ERROR, "Hilfe kommt noch. (Nicht implementiert)");
|
||||||
default -> System.out.println("Help is yet to come. (Not implemented)");
|
default -> logger.log(Level.ERROR, "Help is yet to come. (Not implemented)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,17 +70,18 @@ public final class Main {
|
||||||
printVersionInformation();
|
printVersionInformation();
|
||||||
} else if (userData.length == 0) {
|
} else if (userData.length == 0) {
|
||||||
switch (applicationOutputLanguage) {
|
switch (applicationOutputLanguage) {
|
||||||
case GlobalConf.langGerman -> System.err.println("FATAL: " +
|
case GlobalConf.langGerman -> logger.log(Level.ERROR,
|
||||||
"Es wurde keine Uhrzeit angegeben.");
|
"Es wurde keine Uhrzeit angegeben.");
|
||||||
default -> System.err.println("FATAL: No target time was " +
|
default -> logger.log(Level.ERROR, "No target time" +
|
||||||
|
" was " +
|
||||||
"provided.");
|
"provided.");
|
||||||
}
|
}
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
} else if (userData.length > 1) {
|
} else if (userData.length > 1) {
|
||||||
switch (applicationOutputLanguage) {
|
switch (applicationOutputLanguage) {
|
||||||
case GlobalConf.langGerman -> System.err.println("FATAL: " +
|
case GlobalConf.langGerman -> logger.log(Level.ERROR,
|
||||||
"Zu viele Argumente wurden angegeben.");
|
"Zu viele Argumente wurden angegeben.");
|
||||||
default -> System.err.println("FATAL: Too many arguments " +
|
default -> logger.log(Level.ERROR, "Too many arguments " +
|
||||||
"provided.");
|
"provided.");
|
||||||
}
|
}
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@ -88,7 +91,7 @@ public final class Main {
|
||||||
Sleep.waitUntilTimeStamp(target);
|
Sleep.waitUntilTimeStamp(target);
|
||||||
}
|
}
|
||||||
} catch (final ParseException e) {
|
} catch (final ParseException e) {
|
||||||
System.getLogger("main").log(System.Logger.Level.ERROR, "Parsing " +
|
System.getLogger("main").log(Level.ERROR, "Parsing " +
|
||||||
"of arguments failed and the program cannot continue.", e);
|
"of arguments failed and the program cannot continue.", e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.FormatStyle;
|
import java.time.format.FormatStyle;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import static java.lang.System.Logger.Level;
|
||||||
|
|
||||||
public final class TimeCalculator {
|
public final class TimeCalculator {
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ public final class TimeCalculator {
|
||||||
.formatted(formattedTimeStamp);
|
.formatted(formattedTimeStamp);
|
||||||
default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp);
|
default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp);
|
||||||
};
|
};
|
||||||
System.out.println(msg);
|
System.getLogger("timecalculator").log(Level.INFO, msg);
|
||||||
|
|
||||||
return userTimeInputFinal;
|
return userTimeInputFinal;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue