LoggingApi
An API for logging and log formatting
Last updated | 10 months ago |
Total downloads | 703 |
Total rating | 1 |
Categories | Mods Tools Libraries BepInEx |
Dependency string | QtheConqueror-LoggingApi-1.0.2 |
Dependants | 0 other packages depend on this package |
This mod requires the following mods to function
BepInEx-BepInExPack
BepInEx pack for Mono Unity games. Preconfigured and ready to use.
Preferred version: 5.4.2100README
LoggingApi
Please report any issues here
Overview
Offers simple methods for adding debug logs to method calls. Also provides a variety of log formatting options to users.
Game Installation
Drag the LoggingApi.dll
to your BepInEx/plugins
folder, or just install the mod via a Thunderstore mod loader.
Table of Contents
Features
Source of log messages
Call trace when viewing debug logs
Development Usage
Add the following to your project's .csproj
file, replacing [FILEPATH]
with the path to the LoggingApi.dll
<ItemGroup>
<Reference Include="LoggingApi">
<HintPath>[FILEPATH]\LoggingApi.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
Logger Class
New loggers are created using a ManualLogSource
and LogLevel
.
- The log source is typically your plugins
base.Logger
- It is recommended to use pass a log level set by a config for your plugin.
- This allows user to change the level of logs shown.
- View the BepInEx documentation on how to create configs.
Normal Logs
Here is an example of how to set up a global logger for your plugin.
public class Plugin : BaseUnityPlugin
{
internal static LoggingApi.Logger MyLogger; // Global logger for the plugin
internal static ConfigEntry<LogLevel> ConfigLogLevel; // Config to control which logs are shown
...
private void Awake()
{
MyLogger = LoggingApi.Logger(base.Logger, ConfigLogLevel) // Create a new logger
MyLogger.Log(LogLevel.Message, "Hello World!")
MyLogger.LogMessage("Hello World!")
}
}
// Some other class in the plugin assembly
class SomeOtherAssembly
{
public void SomeMethod()
{
Plugin.MyLogger.LogMessage("Hello World!")
}
}
Logging Calls
With the logger class you can log all calls to members of a type or just specific members of the type.
public class Plugin : BaseUnityPlugin
{
internal static LoggingApi.Logger MyLogger; // Global logger for the plugin
internal static ConfigEntry<LogLevel> ConfigLogLevel; // Config to control which logs are shown
...
private void Awake()
{
MyLogger = LoggingApi.Logger(base.Logger, ConfigLogLevel) // Create a new logger
MyLogger.LogAllCalls(typeof(SomeOtherAssembly)) // All type members
MyLogger.LogCalls(typeof(SomeOtherAssembly), LoggingApi.SearchFlags.Public) // Only public type members
}
}
// Some other class in the plugin assembly
class SomeOtherAssembly
{
public void SomeMethod()
{
...
}
}
SearchFlags Enum
Flags to filter which type members are included in a search.