mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
Log can now handle like String::format
This commit is contained in:
parent
dcd61d4d41
commit
82cd21ddf9
@ -24,7 +24,7 @@ public class StaticConfiguration {
|
||||
public static boolean SKIP_MOJANG_AUTHENTICATION = false; // disables all connections to mojang
|
||||
public static boolean COLORED_LOG = true; // the log should be colored with ANSI (does not affect base components)
|
||||
public static boolean LOG_RELATIVE_TIME = false; // prefix all log messages with the relative start time in milliseconds instead of the formatted time
|
||||
public static boolean VERBOSE_ENTITY_META_DATA_LOGGING = false; // if true, the entity meta data is getting serial
|
||||
public static boolean VERBOSE_ENTITY_META_DATA_LOGGING = false; // if true, the entity meta data is getting serialized
|
||||
public static String HOME_DIRECTORY;
|
||||
|
||||
static {
|
||||
|
@ -45,18 +45,24 @@ public class Log {
|
||||
}, "Log").start();
|
||||
}
|
||||
|
||||
public static void log(LogLevels level, String message, RGBColor color) {
|
||||
log(level, "", message, color);
|
||||
public static void log(LogLevels level, RGBColor color, Object message, Object... format) {
|
||||
log(level, "", color, message, format);
|
||||
}
|
||||
|
||||
public static void log(LogLevels level, String prefix, String message, RGBColor color) {
|
||||
if (message.isBlank()) {
|
||||
return;
|
||||
}
|
||||
public static void log(LogLevels level, String prefix, RGBColor color, Object message, Object... format) {
|
||||
if (level.ordinal() > Log.level.ordinal()) {
|
||||
// log level too low
|
||||
return;
|
||||
}
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
if (message instanceof String string) {
|
||||
if (string.isBlank()) {
|
||||
return;
|
||||
}
|
||||
message = String.format(string, format);
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("[");
|
||||
if (StaticConfiguration.LOG_RELATIVE_TIME) {
|
||||
@ -86,8 +92,8 @@ public class Log {
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void game(String message) {
|
||||
log(LogLevels.GAME, message, ChatColors.GREEN);
|
||||
public static void game(Object message, Object... format) {
|
||||
log(LogLevels.GAME, ChatColors.GREEN, message, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,8 +101,8 @@ public class Log {
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void fatal(String message) {
|
||||
log(LogLevels.FATAL, message, ChatColors.DARK_RED);
|
||||
public static void fatal(Object message, Object... format) {
|
||||
log(LogLevels.FATAL, ChatColors.DARK_RED, message, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,8 +110,8 @@ public class Log {
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void warn(String message) {
|
||||
log(LogLevels.WARNING, message, ChatColors.RED);
|
||||
public static void warn(Object message, Object... format) {
|
||||
log(LogLevels.WARNING, ChatColors.RED, message, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,8 +119,8 @@ public class Log {
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void debug(String message) {
|
||||
log(LogLevels.DEBUG, message, ChatColors.GRAY);
|
||||
public static void debug(Object message, Object... format) {
|
||||
log(LogLevels.DEBUG, ChatColors.GRAY, message, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,8 +128,8 @@ public class Log {
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void verbose(String message) {
|
||||
log(LogLevels.VERBOSE, message, ChatColors.YELLOW);
|
||||
public static void verbose(Object message, Object... format) {
|
||||
log(LogLevels.VERBOSE, ChatColors.YELLOW, message, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,8 +137,8 @@ public class Log {
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void protocol(String message) {
|
||||
log(LogLevels.PROTOCOL, message, ChatColors.BLUE);
|
||||
public static void protocol(Object message, Object... format) {
|
||||
log(LogLevels.PROTOCOL, ChatColors.BLUE, message, format);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,10 +146,20 @@ public class Log {
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void mojang(String message) {
|
||||
log(LogLevels.MOJANG, message, ChatColors.AQUA);
|
||||
public static void mojang(Object message, Object... format) {
|
||||
log(LogLevels.MOJANG, ChatColors.AQUA, message, format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs all general infos, that are more or less important to the user (connecting to server, ...)
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void info(Object message, Object... format) {
|
||||
log(LogLevels.INFO, ChatColors.WHITE, message, format);
|
||||
}
|
||||
|
||||
|
||||
public static LogLevels getLevel() {
|
||||
return level;
|
||||
}
|
||||
@ -156,15 +172,6 @@ public class Log {
|
||||
Log.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs all general infos, that are more or less important to the user (connecting to server, ...)
|
||||
*
|
||||
* @param message Raw message to log
|
||||
*/
|
||||
public static void info(String message) {
|
||||
log(LogLevels.INFO, message, ChatColors.WHITE);
|
||||
}
|
||||
|
||||
public static boolean printException(Exception exception, LogLevels minimumLogLevel) {
|
||||
// ToDo: log to file, print also exceptions that are not printed with this method
|
||||
if (Log.getLevel().ordinal() >= minimumLogLevel.ordinal()) {
|
||||
|
@ -25,31 +25,31 @@ public class Logger {
|
||||
this.modName = modName;
|
||||
}
|
||||
|
||||
public void log(LogLevels level, String message, RGBColor color) {
|
||||
Log.log(level, String.format("[%s] ", modName), message, color);
|
||||
public void log(LogLevels level, RGBColor color, Object message, Object... format) {
|
||||
Log.log(level, String.format("[%s] ", modName), color, message, format);
|
||||
}
|
||||
|
||||
public void game(String message) {
|
||||
log(LogLevels.GAME, message, ChatColors.GREEN);
|
||||
public void game(Object message, Object... format) {
|
||||
log(LogLevels.GAME, ChatColors.GREEN, message, format);
|
||||
}
|
||||
|
||||
public void fatal(String message) {
|
||||
log(LogLevels.FATAL, message, ChatColors.DARK_RED);
|
||||
public void fatal(Object message, Object... format) {
|
||||
log(LogLevels.FATAL, ChatColors.DARK_RED, message, format);
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
log(LogLevels.INFO, message, ChatColors.WHITE);
|
||||
public void info(Object message, Object... format) {
|
||||
log(LogLevels.INFO, ChatColors.WHITE, message, format);
|
||||
}
|
||||
|
||||
public void warn(String message) {
|
||||
log(LogLevels.WARNING, message, ChatColors.RED);
|
||||
public void warn(Object message, Object... format) {
|
||||
log(LogLevels.WARNING, ChatColors.RED, message, format);
|
||||
}
|
||||
|
||||
public void debug(String message) {
|
||||
log(LogLevels.DEBUG, message, ChatColors.GRAY);
|
||||
public void debug(Object message, Object... format) {
|
||||
log(LogLevels.DEBUG, ChatColors.GRAY, message, format);
|
||||
}
|
||||
|
||||
public void verbose(String message) {
|
||||
log(LogLevels.VERBOSE, message, ChatColors.YELLOW);
|
||||
public void verbose(Object message, Object... format) {
|
||||
log(LogLevels.VERBOSE, ChatColors.YELLOW, message, format);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user