Getting Started (Logging) - MeAlam1/BlueLib GitHub Wiki
Getting Started with Logging
Overview
The BaseLogger
class in BlueLib provides a structured and versatile logging system that includes various log levels, allowing for precise tracking and debugging. This setup is tailored for BlueLib’s internal operations and is useful for keeping logs organized in library development.
The BaseLogLevel
class introduces additional custom levels, including INFO
, ERROR
, WARNING
, and SUCCESS
. Notably, it includes the BlueLib
log level, intended specifically for library-related messages within BlueLib.
BlueLib
Logging Level
Important Note: Library-Specific While modders are free to utilize all logging levels and methods provided by BlueLib, the BlueLib
level and the logBluelib
method are specifically intended for library operations. They help maintain internal logs that are pertinent to BlueLib itself, such as debugging library-specific functionality or tracking library performance.
BlueLib
Level: Reserved for messages directly related to BlueLib’s internal processes. Using this level for mod-specific operations is not recommended, as it may obscure critical library logs.logBluelib
Method: A targeted logging method designed to log messages at theBlueLib
level, ensuring they stand out as library-specific entries in the log files.
For Mod Developers
If you are developing a mod, avoid the BlueLib
logging level and the logBluelib
method to keep logs distinct and organized. Instead, use other log levels such as INFO
, ERROR
, Warning
, or SUCCESS
for mod-specific logs. This practice will help in distinguishing mod operations from the BlueLib library’s internal functionality.
Getting Started
-
Setting Up Logging
You can enable and disable the Logging through the Config that we setup! -
Using Log Levels
TheBaseLogLevel
class provides these primary levels:BaseLogLevel.INFO
: Standard informational logs.BaseLogLevel.ERROR
: Error messages.BaseLogLevel.WARNING
: Warnings.BaseLogLevel.SUCCESS
: Success messages.- Note:
BaseLogLevel.BlueLib
is for library-specific logs and should generally be avoided for mod operations.
-
Component-Based Logging
All messages passed into the logger useComponent
instances, allowing for styled, localized, and translatable text in the logs
Example
// Log an info message
BaseLogger.log(BaseLogLevel.INFO, Component.literal("Application started successfully."));
// Log an error with an exception
BaseLogger.log(BaseLogLevel.ERROR, Component.literal("An error occurred during processing."), new RuntimeException("Sample Exception"));
Key Points
- Global Control: Enable or disable logging globally.
- Custom Log Levels: Utilize custom log levels for mod development while reserving
BlueLib
for library-only logs. - Component System**: Logging uses Minecraft’s Component system to support translations and styled messages.
- Efficient Error Tracking: Log messages with exceptions for easier troubleshooting.
This setup offers a robust and customizable logging system for BlueLib, providing clarity and consistency across both library and mod development contexts. For further information and advanced customization options, refer to the official Discord community where you can seek help, share experiences, and learn from other developers.