EquinoxsDebugTools
A library that solves logging issues and provides debugging tools
Screenshots 1 screenshots
About this mod Author’s original text
Equinox's Debug Tools
Description
This library's primary purpose is to solve the issue of having debug logging in release versions of our mods. Doing this with simple Log.Debug() calls is impractical, as logs end up full of spam, so we delete all our debug logging before release, only to add it back in when someone has an issue that we can't replicate. We could have our logging controlled by bools in the source, but this is a lot of effort and it's easy to forget to set them to false, so this library automates that process.
By using this library, all your debug logging will automatically be disabled when a player installs your mod. Then when they run into issues, you can tell them which config option to enable in order to get the debug info you need.
This library also provides several other functions that are helpful for debugging.
Usage
Log()
public static void Log(
string category,
string message
)
This function logs the message given in the argument if the player has enabled debug messages for the given category. Using my MapHotkey mod as an example:
In my mod is the line,.Log("Zoom Updates", "Set zoom level to 6400");. The first time that EDT see's a category ("Zoom Updates"), it creates a config entry like this:
[Mods.MapHotkey]
Whether debug messages should be logged for MapHotkey - Zoom Updates
Setting type: Boolean
Default value: false
Debug Zoom Updates = false
Since this value defaults to false, calls to () that use the category 'Zoom Updates' will be ignored. If a player has an issue, I can tell them to enable this particular config entry to generate debug information without needing to send them a new version with new or enabled logging. Once the player has enabled this option, I will see this in their log:
[Debug:EquinoxsDebugTools] [Zoom Updtes|MapHotkey.MapHotkeyPlugin.Update()]: Set zoom level to 6400
The message is given a prefix with the format:
[Category|Calling Function Path/Name]:
This is to help you see where the message came from in case you have similar debug statements in different funtions.
EDT has a config entry called 'Developer Mode'. When this is set to true, new config entries generated by EDT will default to. Set this entry to to avoid having to manually enable config entries while working on mods.
PacedLog()
public static void PacedLog(
string category,
string message,
float delaySeconds = 0f
)
This function works in the same way as above, but it also prevents any other PacedLog() messages from the same function being logged until the delay has ended. This is useful to use in Update() functions as logging every frame can cause performance issues that make developement very difficult, as well as bury important messages in spam.
If you want to log multiple things in an Update() function, for all but the last write:
EDT.Logging.PacedLog("Category", "My Message");
Then for your last one in the function, specify the delay before the next group are sent:
EDT.Logging.PacedLog("Category", "Last Message In Function", 1f);
SetPacedLogDelay()
public static void SetPacedLogDelay(
float delaySeconds
)
This function sets the delay that must occur before any more PacedLog() messages from the same function are logged. Use this at the end of your function if the last PacedLog() call is in a loop.
Example:
void Update(){
for (int i = 0; i ) {
EDT.Logging.PacedLog("Category", $"My Message Num {i}");
}
EDT.Logging.SetPacedLogDelay(1f)
}
NullCheck()
public static bool NullCheck(
object obj,
string name,
bool shouldLog = false
)
This function can be used to check if the provided object is null and log the result. It's a little cleaner to use this than multiple manual null checks if there's more than one to do in a function.
Returns if is not null. Think of this function as a test, see example use for a better explanation.
Note: If is null, a warning level messaeg will always be logged, regardless of.
Note: Code examples from this point on are written for Techtonica's code
Install & use Install: follow the bundled instructions
- Unzip the archive from playbuff and read the bundled readme / instructions first.
- Most mods rely on the game's mod loader — the usual route is a community mod manager (such as r2modman): pick this game, install, and it handles the loader and dependencies.
- For a manual install, put the mod files into the matching Mod / plugins folder inside the game directory.
- Launch the game to confirm it loaded; mods with listed dependencies need those installed as well.
Install locations vary a lot between mods — the bundled readme is the most reliable guide.