From 6cfa2874bcda4694391735a0857bb1f3a21ebee4 Mon Sep 17 00:00:00 2001 From: Ztrolix Date: Sat, 28 Dec 2024 11:48:15 +1100 Subject: [PATCH] Fixed Logger Util --- .../java/dev/xdpxi/xdlib/util/Logger.java | 79 +++---------------- 1 file changed, 13 insertions(+), 66 deletions(-) diff --git a/common/src/main/java/dev/xdpxi/xdlib/util/Logger.java b/common/src/main/java/dev/xdpxi/xdlib/util/Logger.java index f71c174..6e8c36e 100644 --- a/common/src/main/java/dev/xdpxi/xdlib/util/Logger.java +++ b/common/src/main/java/dev/xdpxi/xdlib/util/Logger.java @@ -1,82 +1,29 @@ package dev.xdpxi.xdlib.util; -import org.apache.logging.log4j.LogManager; +import dev.xdpxi.xdlib.Constants; +import org.slf4j.LoggerFactory; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -/** - * A utility class for logging various log levels using Log4j. - * Provides methods for logging messages at different severity levels: debug, info, warn, and error. - */ public class Logger { - /** - * A map to hold loggers for each package name. - */ - private static final Map PACKAGE_LOGGERS = new ConcurrentHashMap<>(); + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Constants.MOD_ID); - /** - * The logger instance used for logging messages. - * This is initialized with an empty string as the logger name. - */ - public static org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger("default"); - - /** - * Sets up the logger for a specific package with a custom modID. - * This method should be called before any log messages are logged to initialize the logger for the package. - * - * @param packageName The name of the package. - * @param modID The mod ID to be used as the logger name. - */ - public static void setup(String packageName, String modID) { - PACKAGE_LOGGERS.put(packageName, LogManager.getLogger(modID)); - } - - /** - * Gets the logger for the calling class's package. - * If no specific logger is set up, a default logger for the root package is returned. - * - * @return The logger instance for the calling class's package. - */ - private static Logger getLogger() { - String callingPackage = new Throwable().getStackTrace()[2].getClassName(); - String packageName = callingPackage.substring(0, callingPackage.lastIndexOf('.')); - return (Logger) PACKAGE_LOGGERS.getOrDefault(packageName, LogManager.getLogger("default")); + public static void debug(String message, Object... args) { + LOGGER.debug(message, args); } - /** - * Logs a message at the DEBUG level. - * - * @param log The message to be logged. - */ - public static void debug(String log) { - LOGGER.debug(log); + public static void info(String message, Object... args) { + LOGGER.info(message, args); } - /** - * Logs a message at the INFO level. - * - * @param log The message to be logged. - */ - public static void info(String log) { - LOGGER.info(log); + public static void warn(String message, Object... args) { + LOGGER.warn(message, args); } - /** - * Logs a message at the WARN level. - * - * @param log The message to be logged. - */ - public static void warn(String log) { - LOGGER.warn(log); + public static void error(String message, Object... args) { + LOGGER.error(message, args); } - /** - * Logs a message at the ERROR level. - * - * @param log The message to be logged. - */ - public static void error(String log) { - LOGGER.error(log); + public static void error(String message, Throwable throwable) { + LOGGER.error(message, throwable); } } \ No newline at end of file