/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using UnityEngine; namespace OmiLAXR { /// /// Interface for components that need access to debug logging functionality. /// Provides a standardized way to expose debug logging capabilities. /// public interface IDebugSender { /// /// Gets the DebugLog instance used by this component for logging operations. /// DebugLog DebugLog { get; } } /// /// Delegate for building custom debug messages with optional prefixes. /// Used for advanced message formatting scenarios. /// /// Optional prefix for the message (defaults to "OmiLAXR") /// Formatted debug message string public delegate string BuildMessageResponse(string prefix = "OmiLAXR"); /// /// Centralized debug logging system with consistent message formatting and prefixing. /// Provides categorized logging methods (Print, Error, Warning) with automatic prefix handling. /// Ensures consistent log formatting across the entire OmiLAXR system. /// public sealed class DebugLog { /// /// Prefix string used to identify log messages from this logger instance. /// Appears at the beginning of all messages for easy filtering and identification. /// private readonly string _prefix; /// /// Initializes a new DebugLog instance with the specified prefix. /// /// Prefix string to use for all log messages public DebugLog(string prefix) { _prefix = prefix; } /// /// Default OmiLAXR system logger instance used throughout the framework. /// Provides consistent logging for core system components and behaviors. /// public static readonly DebugLog OmiLAXR = new DebugLog("OmiLAXR"); /// /// Builds a formatted log message with prefix and optional string formatting. /// Internal helper method used by all public logging methods. /// /// Prefix to use for this message /// Message format string /// Optional parameters for string formatting /// Fully formatted log message with prefix private static string BuildMessage(string prefix, string message, params object[] ps) => $"[{prefix}]: {((ps != null && ps.Length > 0) ? string.Format(message, ps) : message)}"; /// /// Logs an informational message to the Unity console. /// Supports string formatting with optional parameters. /// /// Message format string /// Optional parameters for string formatting public void Print(string message, params object[] ps) => Debug.Log(BuildMessage(_prefix, message, ps)); /// /// Logs an error message to the Unity console. /// Supports string formatting with optional parameters. /// /// Error message format string /// Optional parameters for string formatting public void Error(string message, params object[] ps) => Debug.LogError(BuildMessage(_prefix, message, ps)); /// /// Logs a warning message to the Unity console. /// Supports string formatting with optional parameters. /// /// Warning message format string /// Optional parameters for string formatting public void Warning(string message, params object[] ps) => Debug.LogWarning(BuildMessage(_prefix, message, ps)); /// /// Logs an informational message with an associated Unity Object context. /// The context object will be highlighted in the Unity console when the message is clicked. /// /// Message to log /// Unity Object to associate with this log message public void Print(string message, Object context) => Debug.Log(BuildMessage(_prefix, message), context); /// /// Logs an error message with an associated Unity Object context. /// The context object will be highlighted in the Unity console when the message is clicked. /// /// Error message to log /// Unity Object to associate with this error message public void Error(string message, Object context) => Debug.LogError(BuildMessage(_prefix, message), context); /// /// Logs a warning message with an associated Unity Object context. /// The context object will be highlighted in the Unity console when the message is clicked. /// /// Warning message to log /// Unity Object to associate with this warning message public void Warning(string message, Object context) => Debug.LogWarning(BuildMessage(_prefix, message), context); } }