LoggingApi

版本 v1.0.2·更新於 2024-02-04

An API for logging and log formatting

模組介紹 作者原文

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.

安裝與使用 安裝:BepInEx 外掛

  1. 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
  2. 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
  3. 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
  4. 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。

帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

BepInEx-BepInExPack

檔案與校驗

檔案名稱
LoggingApi-1.0.2.zip
檔案大小
500.6 KiB