Skip to main content

LoggingLauncher

Important Attention Reminder

Coding Style wiki


LoggingLauncher is the log deployment launcher of LoggingSystem (a MonoBehaviour singleton). It is responsible for initializing loggers and loading the config file (StreamingAssets), and provides dynamic configuration APIs for the global (Master) and per-logger settings; you can import the LoggingLauncher Prefab via Samples and drag it into the scene to activate it (only needs to be activated once).

NamespaceOxGKit.LoggingSystem
Typepublic class LoggingLauncher : MonoBehaviour
SourceLoggingLauncher.cs
using OxGKit.LoggingSystem;

Attention Methods marked [StartCoroutine] are convenience calls that wrap a coroutine; each method has a corresponding [Async] version (IEnumerator), which you can yield in your own coroutine to await completion.

Quick Start

using OxGKit.LoggingSystem;

// The LoggingLauncher Prefab is already placed in the scene (Initialize On Awake)
// -> Automatically runs InitLoggers + loads the StreamingAssets config file

// Dynamically configure a single logger
LoggingLauncher.ConfigureLogger("Game.Logger", true, LogLevel.LogWarning | LogLevel.LogError);

// Master toggle
LoggingLauncher.ToggleMasterLogging(false);

// Custom config (dynamically configure loggers)
var loggersConfig = new LoggersConfig
(
new LoggerSettings("Game.Logger", true, LogLevel.All)
);
LoggingLauncher.SetLoggersConfig(loggersConfig);

General Rules

Initialization Flow

  1. Initialize On Awake (default): LoggingLauncher automatically runs InitLoggers in Awake (collecting all Logging implementations via reflection) and tries to load the StreamingAssets config file.
  2. Manual initialization (HybridCLR): Uncheck the "Initialize On Awake" option in the Inspector, call CreateLogger yourself to register loggers one by one, and finally call TryLoadLoggers to apply the configuration.

Important When working with HybridCLR where the main project and the hot-update project are separated, you must manually split the creation of the Loggers initialization flow into AOT and Hotfix parts (the Hotfix project's Loggers must be initialized in the Hotfix project).

Config Effective Conditions

Important Loggers are loaded and output only under UNITY_EDITOR or when the OXGKIT_LOGGER_ON symbol is defined; otherwise the message Not enabled LoggingSystem by symbol [OXGKIT_LOGGER_ON] is shown.


Members

MemberDescription
public bool initLoggersOnAwakeWhether to initialize automatically in Awake (Inspector: Initialize On Awake); must be unchecked when initializing manually with HybridCLR.
public LoggersConfig loggersConfigThe current logger configuration data (LoggersConfig).
public static ConfigFileType currentConfigFileTypeThe current config file type (Json / Bytes), defaults to Bytes.

Logger Management

Method Overview

MethodDescription
InitLoggersCollects and initializes all loggers via reflection.
ClearLoggersClears all registered loggers.
CreateLoggerManually registers a single logger (HybridCLR flow).
TryInitLoggersInitializes all loggers and loads the config file.
TryLoadLoggersReloads logger settings from the config file.

InitLoggers

public static void InitLoggers()

Collects all Logging implementation classes via reflection and creates instances (including LoggerName name and override handling).

ClearLoggers

public static void ClearLoggers()

Clears all registered logger caches.

CreateLogger

public static void CreateLogger<TLogging>() where TLogging : Logging, new()

Manually registers a single logger, used for the manually split AOT / Hotfix initialization flow with HybridCLR (avoids reflection failing to collect types from the hot-update project).

// HybridCLR (must uncheck the "Initialize On Awake" option on LoggingLauncher):
LoggingLauncher.CreateLogger<LoggingDemoLogger1>();
LoggingLauncher.CreateLogger<LoggingDemoLogger2>();
LoggingLauncher.TryLoadLoggers();

TryInitLoggers

// [StartCoroutine]
public static void TryInitLoggers()

// [Async]
public static IEnumerator TryInitLoggersAsync()

Initializes all loggers (InitLoggers) and loads the StreamingAssets config file to apply the settings (equivalent to the automatic Awake initialization flow).

TryLoadLoggers

// [StartCoroutine]
public static void TryLoadLoggers()

// [Async]
public static IEnumerator TryLoadLoggersAsync()

Reloads logger settings from the config file; this method must be called to reload after adding or removing a Logger.


Global Config (Master)

Method Overview

MethodDescription
ToggleMasterLoggingMaster toggle (enables/disables all loggers).
LevelMasterLoggingSets the global log level.
ColorMasterLoggingSets the global log color mode.

ToggleMasterLogging

// [StartCoroutine]
public static void ToggleMasterLogging(bool logMainActive)

// [Async]
public static IEnumerator ToggleMasterLoggingAsync(bool logMainActive)

Switches the master toggle (Master Logging Toggle); when off, no logger outputs anything.

LevelMasterLogging

// [StartCoroutine]
public static void LevelMasterLogging(LogLevel logMainLevel)

// [Async]
public static IEnumerator LevelMasterLoggingAsync(LogLevel logMainLevel)

Sets the global level (Master Logging Level); it takes effect as the intersection with the per-logger levels (see the level rules table).

ColorMasterLogging

// [StartCoroutine]
public static void ColorMasterLogging(LogColor logMainColor)

// [Async]
public static IEnumerator ColorMasterLoggingAsync(LogColor logMainColor)

Sets the global color mode (Master Logging Color); the stricter of it and the per-logger color mode takes effect (see the color rules table).


Per-Logger Config

Method Overview

MethodDescription
ConfigureLoggerConfigures the toggle/level/color of the specified logger.
ConfigureAllLoggersConfigures the toggle/level/color of all loggers at once.
SetLoggersConfigOverwrites the current config with a custom LoggersConfig and reloads.

ConfigureLogger

// [StartCoroutine]
public static void ConfigureLogger(string loggerName, bool logActive, LogLevel logLevel = LogLevel.All, LogColor logColor = LogColor.EditorOnly)

// [Async]
public static IEnumerator ConfigureLoggerAsync(string loggerName, bool logActive, LogLevel logLevel = LogLevel.All, LogColor logColor = LogColor.EditorOnly)

Configures the toggle, level, and color mode of the logger with the specified name; automatically reloads after configuring.

LoggingLauncher.ConfigureLogger("Game.Logger", true, LogLevel.LogWarning | LogLevel.LogError);

ConfigureAllLoggers

// [StartCoroutine]
public static void ConfigureAllLoggers(bool logActive, LogLevel logLevel = LogLevel.All, LogColor logColor = LogColor.EditorOnly)

// [Async]
public static IEnumerator ConfigureAllLoggersAsync(bool logActive, LogLevel logLevel = LogLevel.All, LogColor logColor = LogColor.EditorOnly)

Configures the toggle, level, and color mode of all loggers at once; automatically reloads after configuring.

SetLoggersConfig

// [StartCoroutine]
public static void SetLoggersConfig(LoggersConfig loggersConfig)

// [Async]
public static IEnumerator SetLoggersConfigAsync(LoggersConfig loggersConfig)

Overwrites the current config with a custom LoggersConfig and reloads (dynamically configure loggers).

var loggersConfig = new LoggersConfig
(
new LoggerSettings("LoggingDemo.Logger1", true, LogLevel.LogDebug),
new LoggerSettings("LoggingDemo.Logger2", true, LogLevel.LogWarning),
new LoggerSettings("LoggingDemo.Logger3", true, LogLevel.Off)
);
LoggingLauncher.SetLoggersConfig(loggersConfig);

Config Reload

Method Overview

MethodDescription
ReloadLoggersConfig(Instance) Re-initializes loggers and syncs the config list.
ReloadFromLoggersConfig(Instance) Reloads the config from the config file.
ResetLoggersConfig(Instance) Clears and rebuilds the config.
ReloadLoggersConfigAndSetSyncs the config list with the current logger implementations (add/remove comparison).

ReloadLoggersConfig

// [StartCoroutine]
public void ReloadLoggersConfig(Action<LoggersConfig> result = null)

// [Async]
public IEnumerator ReloadLoggersConfigAsync(Action<LoggersConfig> result = null)

(Instance method) Re-initializes loggers and syncs the config list; when finished, returns the current config via result.

ReloadFromLoggersConfig

// [StartCoroutine]
public void ReloadFromLoggersConfig(Action<LoggersConfig> result = null)

// [Async]
public IEnumerator ReloadFromLoggersConfigAsync(Action<LoggersConfig> result = null)

(Instance method) Reloads the config from the StreamingAssets config file.

ResetLoggersConfig

// [StartCoroutine]
public void ResetLoggersConfig(Action<LoggersConfig> result = null)

// [Async]
public IEnumerator ResetLoggersConfigAsync(Action<LoggersConfig> result = null)

(Instance method) Clears the current config and rebuilds it with default values.

ReloadLoggersConfigAndSet

public static void ReloadLoggersConfigAndSet(LoggersConfig loggersConfig, Action<LoggersConfig> result)

Compares and syncs the passed-in config list with the currently registered logger implementations (automatically adds new loggers and removes loggers that no longer exist); when finished, returns via result.