LoggingApi
An API for logging and log formatting
About this mod Author’s original text
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 mod loader.
Table of Contents
- Features
- Development Usage
- Logger Class
- Normal Logs
- Logging Calls
- SearchFlags Enum
Features
Source of log messages
Call trace when viewing debug logs
Images were taken in VSCode/Codium with the FiraCode font
Development Usage
Add the following to your project's.csproj file, replacing [FILEPATH] with the path to the LoggingApi.dll
[FILEPATH]\LoggingApi.dll
false
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 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 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.
Install & use Install: BepInEx plugin
- The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
- Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
- Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
- Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.
Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.
Install these first, or the mod will not work: