Skip to main content

LoggersConfig

Important Attention Reminder

Coding Style wiki


LoggersConfig is the logger configuration data of LoggingSystem (serializable), containing the global toggle/level/color and the settings list of each logger (LoggerSettings); the config can be saved as a StreamingAssets config file (Cipher/Plaintext), or applied dynamically at runtime via LoggingLauncher.SetLoggersConfig.

NamespaceOxGKit.LoggingSystem
Type[Serializable] public class LoggersConfig
SourceLoggersConfig.cs
using OxGKit.LoggingSystem;

Quick Start

// Create a config (multiple LoggerSettings can be passed in)
var loggersConfig = new LoggersConfig
(
new LoggerSettings("Game.Logger", true, LogLevel.All),
new LoggerSettings("Net.Logger", true, LogLevel.LogError, LogColor.Enabled)
);

// Apply the config and reload
LoggingLauncher.SetLoggersConfig(loggersConfig);

Members

MemberDescription
public bool logMainActiveMaster toggle (Inspector: Master Logging Toggle), defaults to true.
public LogLevel logMainLevelGlobal level (Inspector: Master Logging Level), defaults to LogLevel.All.
public LogColor logMainColorGlobal color mode (Inspector: Master Logging Color), defaults to LogColor.EditorOnly.
public List<LoggerSettings> loggerSettingsThe config list of each logger.

Constructors

public LoggersConfig()
public LoggersConfig(params LoggerSettings[] loggerSettings)

Methods

MethodDescription
ClearLoggerSettingsClears all logger settings.
AddLoggerSettingsAdds a logger setting entry.
RemoveLoggerSettingsRemoves a logger setting entry.

ClearLoggerSettings

public void ClearLoggerSettings()

AddLoggerSettings

public void AddLoggerSettings(LoggerSettings loggerSettings)

RemoveLoggerSettings

public void RemoveLoggerSettings(LoggerSettings loggerSettings)

LoggerSettings

A single logger's configuration (serializable).

Type[Serializable] public class LoggerSettings
SourceLoggerSettings.cs
MemberDescription
public string loggerNameLogger name (read-only in the Inspector).
public bool logActiveLogger toggle.
public LogLevel logLevelLogger level, defaults to All.
public LogColor logColorLogger color mode, defaults to EditorOnly.
public LoggerSettings(string loggerName, bool logActive)
public LoggerSettings(string loggerName, bool logActive, LogLevel logLevel)
public LoggerSettings(string loggerName, bool logActive, LogLevel logLevel, LogColor logColor)

LogLevel

Log level (Flags; multiple levels can be combined with |).

[Flags]
public enum LogLevel
{
Off = 0,
LogDebug = 1 << 0,
LogInfo = 1 << 1,
LogWarning = 1 << 2,
LogError = 1 << 3,
LogException = 1 << 4,
All = ~0
}
// Combination example: only output Warning + Error
LoggingLauncher.ConfigureLogger("Game.Logger", true, LogLevel.LogWarning | LogLevel.LogError);

Attention The effective rule is the intersection of the global and per-logger settings (G ∩ P); see the level rules table.


LogColor

Log color mode.

public enum LogColor
{
Disabled = 0, // Colors disabled
Enabled = 1, // Colors always enabled
EditorOnly = 2 // Colors enabled only in the Editor (automatically stripped in release builds)
}

Attention The effective rule takes the stricter of the global and per-logger settings; see the color rules table.


ConfigFileType

Config file type.

public enum ConfigFileType
{
Json, // JSON [Plaintext]
Bytes // BYTES [Cipher]
}

LoggerNameAttribute

Logger name attribute, used to customize the logger name and override a logger with the same name (Override).

Type[AttributeUsage(AttributeTargets.Class)] public class LoggerNameAttribute : Attribute
SourceLoggerNameAttribute.cs
MemberDescription
public string loggerNameLogger name.
public bool isOverrideWhether to override the logger with the same name.
public LoggerNameAttribute(string loggerName)
public LoggerNameAttribute(string loggerName, bool isOverride)
[LoggerName("MyLogger")]
public class MyLogger1 : Logging { }

// Use same name to override MyLogger1
[LoggerName("MyLogger", true)]
public class OverrideMyLogger1 : Logging { }

LoggingSettings

The settings file (ScriptableObject) of LoggingSystem, allowing customization of the config file name, extension, and cipher key.

Typepublic class LoggingSettings : ScriptableObject
SourceLoggingSettings.cs
MemberDescription
public const short CIPHER_HEADERConfig file header (0x584F).
public byte cipherConfig file cipher key, defaults to 0x42.
public string loggerCfgNameConfig file name, defaults to "LoggerConfig".
public string loggerCfgExtensionConfig file extension (must include the dot, e.g. .dat, .cfg, .json), defaults to ".dat".
public static LoggingSettings settingsSettings singleton (automatically loaded from Resources; uses default values if none exists).

Reminder Create the settings asset via Right-Click Create/OxGKit/Create Settings/Create Logging Settings in Resources to customize the config file name.