Logging API
PetarLib provides a simple and performant logging system designed for Minecraft mods.
Overview
The logging system consists of:
PLoggerinterface: Defines the logging methods.PLogclass: Implementation that logs to console and optionally to a file.LogConfigclass: Static configuration for global logging settings.LogLevelenum: Defines log levels (DEBUG, INFO, WARN, ERROR, OFF).
Usage
Creating a Logger
import com.petarmc.lib.log.PLog;
import com.petarmc.lib.log.PLogger;
PLogger logger = new PLog("MyMod");
Logging Messages
logger.debug("This is a debug message");
logger.info("This is an info message");
logger.warn("This is a warning");
logger.error("This is an error");
logger.error("Error with exception", exception);
Configuration
Configure logging globally via LogConfig:
import com.petarmc.lib.log.LogConfig;
import com.petarmc.lib.log.LogLevel;
LogConfig.globalLevel = LogLevel.DEBUG;
LogConfig.logToFile = true;
LogConfig.logFilePath = "mymod.log";
LogConfig.globalPrefix = "[MyMod]";
LogConfig.includeTimestamp = true;
LogConfig.includeThread = false;
Log Levels
- DEBUG: Detailed information for developers.
- INFO: General information.
- WARN: Potential issues.
- ERROR: Failures or critical issues.
- OFF: Suppress all logging.
Messages below the globalLevel are ignored.