EquinoxsDebuggingTools
A library that solves logging issues and provides debugging tools
截圖 共 1 張
模組介紹 作者原文
EquinoxsDebuggingTools
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 CreativeFlight mod as an example:
In my mod is the line,.Log("Status", "Flying Started");. The first time that EDT see's a category ("Status"), it creates a config entry like this:
[Mods.CreativeFlight]
Whether debug messages should be logged for CreativeFlight - Status
Setting type: Boolean
Default value: false
Debug Status = false
Since this value defaults to false, calls to () that use the category 'Status' 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:EquinoxsDebuggingTools] [CreativeFlight|Status|CreativeFlight.Jetpack.StopFlight]: Stopped Flying
The message is given a prefix with the format:
[Calling DLL Name|Category|Calling Function 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 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.PacedLog("Category", "My Message");
Then for your last one in the function, specify the delay before the next group are sent:
EDT.PacedLog("Category", "Last Message In Function", 0.25f);
SetPacedLogDelay()
public static void SetPacedLogDelay(
float delaySeconds
)
This function sets the delay that must occur before any more PacedLog() messages are logged. Use this at the end of your Update() function if the last PacedLog() call is in a loop.
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.
Example use:
if(NullCheck(UIManager.instance, "UI Manager"){
if(NullCheck(UIManager.instance.techTreeMenu, "Tech Tree Menu")){
TechTreeNode node = UIManager.instance.techTreeMenu.GridUI.GetNodeByUnlock(...);
}
}
This could also be written using guard clauses:
if(!Null
安裝與使用 安裝:按包內說明操作
- 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
- 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
- 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
- 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。
不同模組的安裝位置差異較大,包內說明是最可靠的依據。