tweaks724/src/main/java/eu/m724/tweaks/DebugLogger.java
2024-12-31 13:34:17 +01:00

51 lines
1.4 KiB
Java

/*
* Copyright (C) 2024 Minecon724
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
* in the project root for the full license text.
*/
package eu.m724.tweaks;
import org.fusesource.jansi.Ansi;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DebugLogger {
static Logger logger;
public static void info(String message) {
log(Level.INFO, message);
}
public static void warning(String message) {
log(Level.WARNING, message);
}
public static void severe(String message) {
log(Level.SEVERE, message);
}
public static void fine(String message) {
log(Level.FINE, message);
}
private static void log(Level level, String message) {
if (logger.getLevel().intValue() > level.intValue()) return;
var caller = Thread.currentThread().getStackTrace()[3].getClassName();
if (caller.startsWith("eu.m724.tweaks."))
caller = caller.substring(15);
message = "[" + caller + "] " + message;
if (level.intValue() < Level.INFO.intValue()) { // levels below info are never logged even if set for some reason
level = Level.INFO;
// colors text gray (cyan is close to gray)
message = Ansi.ansi().fg(Ansi.Color.CYAN).a(message).reset().toString();
}
logger.log(level, message);
}
}