From d4605ec99f85aa426e21e40ff6f0dd13996a50b5 Mon Sep 17 00:00:00 2001 From: tayjay Date: Sun, 1 Mar 2026 11:39:13 -0800 Subject: [PATCH 1/6] feat: add Debug property to all plugins to control `Logger.Debug` default behaviour warn!: plugin developers must set `Debug` in `configs/{PORT}/{Plugin}/properties.yml` for [DEBUG] messages to appear unless they explictly set the `canBePrinted` parameter of the Debug method --- LabApi/Features/Console/Logger.cs | 19 +++++++++++++- .../Features/Configuration/LabApiConfig.cs | 7 ++++++ .../Plugins/Configuration/Properties.cs | 9 +++++++ LabApi/Loader/PluginLoader.cs | 25 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/LabApi/Features/Console/Logger.cs b/LabApi/Features/Console/Logger.cs index e0c59c16..4f56cf73 100644 --- a/LabApi/Features/Console/Logger.cs +++ b/LabApi/Features/Console/Logger.cs @@ -22,12 +22,29 @@ public static class Logger /// The color of the message. public static void Raw(string message, ConsoleColor color) => ServerConsole.AddLog(message, color); + /// + /// An O(1) set of Assemblies that should display Debug messages. + /// Populated automatically by + /// + public static System.Collections.Generic.HashSet DebugEnabled { get; } = new(); + + /// + /// Logs a debug message to the server console. + /// Checks before sending the message. + /// + /// The message to log. + public static void Debug(object message) => Debug(message, Loader.PluginLoader.Config?.DebugOverride == true || DebugEnabled.Contains(Assembly.GetCallingAssembly())); + /// /// Logs a debug message to the server console. /// /// The message to log. /// Whether the message can be printed. - public static void Debug(object message, bool canBePrinted = true) + /// + /// Uses explicit . + /// Can be replaced with the single parameter overload to use Property instead. + /// + public static void Debug(object message, bool canBePrinted) { if (!canBePrinted) { diff --git a/LabApi/Loader/Features/Configuration/LabApiConfig.cs b/LabApi/Loader/Features/Configuration/LabApiConfig.cs index 47bea231..0068f47d 100644 --- a/LabApi/Loader/Features/Configuration/LabApiConfig.cs +++ b/LabApi/Loader/Features/Configuration/LabApiConfig.cs @@ -27,4 +27,11 @@ public class LabApiConfig /// [Description("Whether to allow loading plugins even if they were built for a different major version of LabAPI.")] public bool LoadUnsupportedPlugins { get; set; } + + /// + /// Whether debug logs should appear regardless of pre-plugin properties. + /// + /// + [Description("Whether debug logs should be printed regardless of pre-plugin properties. Only recommended during Plugin development.")] + public bool DebugOverride { get; set; } = false; } diff --git a/LabApi/Loader/Features/Plugins/Configuration/Properties.cs b/LabApi/Loader/Features/Plugins/Configuration/Properties.cs index 0e13acf9..2bb645e1 100644 --- a/LabApi/Loader/Features/Plugins/Configuration/Properties.cs +++ b/LabApi/Loader/Features/Plugins/Configuration/Properties.cs @@ -20,6 +20,15 @@ public class Properties [Description("Whether or not the plugin is enabled.")] public bool IsEnabled { get; set; } = true; + /// + /// Whether should print logs. + /// + /// + /// Using the same naming as EXILED to ease transition for devs moving to LabAPI. + /// + [Description("Whether or not [Debug] log messages should appear. Default is false.")] + public bool Debug { get; set; } = false; + /// /// Whether to allow loading the plugin even if it was built for a different major version of LabAPI. /// diff --git a/LabApi/Loader/PluginLoader.cs b/LabApi/Loader/PluginLoader.cs index 04a75ddd..be53010f 100644 --- a/LabApi/Loader/PluginLoader.cs +++ b/LabApi/Loader/PluginLoader.cs @@ -14,6 +14,8 @@ using System.IO; using System.Linq; using System.Reflection; +using NorthwoodLib.Pools; +using Utils.NonAllocLINQ; namespace LabApi.Loader; @@ -233,6 +235,7 @@ public static void LoadPlugins(IEnumerable files) /// The sorted collection of s. public static void EnablePlugins(IEnumerable plugins) { + List debugAssemblies = ListPool.Shared.Rent(); foreach (Plugin plugin in plugins) { // We try to load the configuration of the plugin @@ -253,9 +256,31 @@ public static void EnablePlugins(IEnumerable plugins) continue; } + // Check if the plugin associated with this assembly wants Debug logs enabled. + if (plugin.Properties?.Debug == true) + { + // This body will not be run on most live servers. + if (Plugins.TryGetValue(plugin, out Assembly asm)) + { + debugAssemblies.AddIfNotContains(asm); + } + } + // We finally enable the plugin EnablePlugin(plugin); } + + // Update the Set of Assemblies that should display Debug level logs. + // It is possible for an Assembly to contain more than 1 plugin, we enable Debug if any 1 plugin in the Assembly requests it. + // This list is only updated when all Plugins are reloaded as to not interfere with Enabled plugins that may still want Debugging. + // On most live servers this loop will be skipped + Logger.DebugEnabled.Clear(); + foreach (var asm in debugAssemblies) + { + Logger.DebugEnabled.Add(asm); + } + + ListPool.Shared.Return(debugAssemblies); } /// From e20e02bb4dff36bd2c795bbb8536804320d70dea Mon Sep 17 00:00:00 2001 From: tayjay Date: Sun, 1 Mar 2026 12:03:35 -0800 Subject: [PATCH 2/6] fix: typo and parameter spacing --- LabApi/Features/Console/Logger.cs | 4 +++- LabApi/Loader/Features/Configuration/LabApiConfig.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/LabApi/Features/Console/Logger.cs b/LabApi/Features/Console/Logger.cs index 4f56cf73..34a3d2d3 100644 --- a/LabApi/Features/Console/Logger.cs +++ b/LabApi/Features/Console/Logger.cs @@ -33,7 +33,9 @@ public static class Logger /// Checks before sending the message. /// /// The message to log. - public static void Debug(object message) => Debug(message, Loader.PluginLoader.Config?.DebugOverride == true || DebugEnabled.Contains(Assembly.GetCallingAssembly())); + public static void Debug(object message) => Debug( + message, + Loader.PluginLoader.Config?.DebugOverride == true || DebugEnabled.Contains(Assembly.GetCallingAssembly())); /// /// Logs a debug message to the server console. diff --git a/LabApi/Loader/Features/Configuration/LabApiConfig.cs b/LabApi/Loader/Features/Configuration/LabApiConfig.cs index 0068f47d..85358e33 100644 --- a/LabApi/Loader/Features/Configuration/LabApiConfig.cs +++ b/LabApi/Loader/Features/Configuration/LabApiConfig.cs @@ -32,6 +32,6 @@ public class LabApiConfig /// Whether debug logs should appear regardless of pre-plugin properties. /// /// - [Description("Whether debug logs should be printed regardless of pre-plugin properties. Only recommended during Plugin development.")] + [Description("Whether debug logs should be printed regardless of per-plugin properties. Only recommended during Plugin development.")] public bool DebugOverride { get; set; } = false; } From 408d7362ee10b5f9c7dab4e8d59273801a8106bd Mon Sep 17 00:00:00 2001 From: tayjay Date: Sun, 1 Mar 2026 12:16:18 -0800 Subject: [PATCH 3/6] fix: removed unneeded loop and List allocation as part of debug setup --- LabApi/Loader/PluginLoader.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/LabApi/Loader/PluginLoader.cs b/LabApi/Loader/PluginLoader.cs index be53010f..b8a8d24b 100644 --- a/LabApi/Loader/PluginLoader.cs +++ b/LabApi/Loader/PluginLoader.cs @@ -235,7 +235,7 @@ public static void LoadPlugins(IEnumerable files) /// The sorted collection of s. public static void EnablePlugins(IEnumerable plugins) { - List debugAssemblies = ListPool.Shared.Rent(); + Logger.DebugEnabled.Clear(); foreach (Plugin plugin in plugins) { // We try to load the configuration of the plugin @@ -262,25 +262,17 @@ public static void EnablePlugins(IEnumerable plugins) // This body will not be run on most live servers. if (Plugins.TryGetValue(plugin, out Assembly asm)) { - debugAssemblies.AddIfNotContains(asm); + if (Logger.DebugEnabled.Add(asm)) + { + // Only want to print when the first plugin in an assembly enables Debug + Logger.Info($"Debug logging enabled for {asm.FullName}"); + } } } // We finally enable the plugin EnablePlugin(plugin); } - - // Update the Set of Assemblies that should display Debug level logs. - // It is possible for an Assembly to contain more than 1 plugin, we enable Debug if any 1 plugin in the Assembly requests it. - // This list is only updated when all Plugins are reloaded as to not interfere with Enabled plugins that may still want Debugging. - // On most live servers this loop will be skipped - Logger.DebugEnabled.Clear(); - foreach (var asm in debugAssemblies) - { - Logger.DebugEnabled.Add(asm); - } - - ListPool.Shared.Return(debugAssemblies); } /// From 62a1b999ef1ff1b8053741999dcaf509d01d30a5 Mon Sep 17 00:00:00 2001 From: tayjay Date: Sun, 1 Mar 2026 12:19:03 -0800 Subject: [PATCH 4/6] fix: typo [Debug] => [DEBUG] in property description --- LabApi/Loader/Features/Plugins/Configuration/Properties.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LabApi/Loader/Features/Plugins/Configuration/Properties.cs b/LabApi/Loader/Features/Plugins/Configuration/Properties.cs index 2bb645e1..4a7dc04b 100644 --- a/LabApi/Loader/Features/Plugins/Configuration/Properties.cs +++ b/LabApi/Loader/Features/Plugins/Configuration/Properties.cs @@ -26,7 +26,7 @@ public class Properties /// /// Using the same naming as EXILED to ease transition for devs moving to LabAPI. /// - [Description("Whether or not [Debug] log messages should appear. Default is false.")] + [Description("Whether or not [DEBUG] log messages should appear in the console. Default is false.")] public bool Debug { get; set; } = false; /// From 77a119ed846e2d6bc8fbd6b684e85063ecf51b10 Mon Sep 17 00:00:00 2001 From: TayTay Date: Sun, 1 Mar 2026 15:14:57 -0800 Subject: [PATCH 5/6] Update LabApi/Loader/PluginLoader.cs Co-authored-by: David --- LabApi/Loader/PluginLoader.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/LabApi/Loader/PluginLoader.cs b/LabApi/Loader/PluginLoader.cs index b8a8d24b..874e53ee 100644 --- a/LabApi/Loader/PluginLoader.cs +++ b/LabApi/Loader/PluginLoader.cs @@ -236,6 +236,7 @@ public static void LoadPlugins(IEnumerable files) public static void EnablePlugins(IEnumerable plugins) { Logger.DebugEnabled.Clear(); + foreach (Plugin plugin in plugins) { // We try to load the configuration of the plugin From 27c65e880095c478f72afb4bd17496e452c191ca Mon Sep 17 00:00:00 2001 From: tayjay Date: Sun, 1 Mar 2026 15:42:16 -0800 Subject: [PATCH 6/6] fix: removing overly verbose and unnecessary comments. fix: removing references to classes used in an old implementation from PluginLoader.cs --- LabApi/Features/Console/Logger.cs | 11 +++-------- LabApi/Loader/Features/Configuration/LabApiConfig.cs | 5 +++-- .../Features/Plugins/Configuration/Properties.cs | 5 +---- LabApi/Loader/PluginLoader.cs | 4 +--- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/LabApi/Features/Console/Logger.cs b/LabApi/Features/Console/Logger.cs index 34a3d2d3..f0b39dc8 100644 --- a/LabApi/Features/Console/Logger.cs +++ b/LabApi/Features/Console/Logger.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Reflection; namespace LabApi.Features.Console; @@ -23,14 +24,12 @@ public static class Logger public static void Raw(string message, ConsoleColor color) => ServerConsole.AddLog(message, color); /// - /// An O(1) set of Assemblies that should display Debug messages. - /// Populated automatically by + /// List of assemblies to display Debug level logs for. /// - public static System.Collections.Generic.HashSet DebugEnabled { get; } = new(); + public static HashSet DebugEnabled { get; } = new(); /// /// Logs a debug message to the server console. - /// Checks before sending the message. /// /// The message to log. public static void Debug(object message) => Debug( @@ -42,10 +41,6 @@ public static void Debug(object message) => Debug( /// /// The message to log. /// Whether the message can be printed. - /// - /// Uses explicit . - /// Can be replaced with the single parameter overload to use Property instead. - /// public static void Debug(object message, bool canBePrinted) { if (!canBePrinted) diff --git a/LabApi/Loader/Features/Configuration/LabApiConfig.cs b/LabApi/Loader/Features/Configuration/LabApiConfig.cs index 85358e33..02216014 100644 --- a/LabApi/Loader/Features/Configuration/LabApiConfig.cs +++ b/LabApi/Loader/Features/Configuration/LabApiConfig.cs @@ -1,4 +1,5 @@ using LabApi.Loader.Features.Paths; +using LabApi.Loader.Features.Plugins.Configuration; using System.Collections.Generic; using System.ComponentModel; @@ -24,14 +25,14 @@ public class LabApiConfig /// /// Whether to allow loading plugins even if they were built for a different major version of LabAPI. /// - /// + /// [Description("Whether to allow loading plugins even if they were built for a different major version of LabAPI.")] public bool LoadUnsupportedPlugins { get; set; } /// /// Whether debug logs should appear regardless of pre-plugin properties. /// - /// + /// [Description("Whether debug logs should be printed regardless of per-plugin properties. Only recommended during Plugin development.")] public bool DebugOverride { get; set; } = false; } diff --git a/LabApi/Loader/Features/Plugins/Configuration/Properties.cs b/LabApi/Loader/Features/Plugins/Configuration/Properties.cs index 4a7dc04b..7910335c 100644 --- a/LabApi/Loader/Features/Plugins/Configuration/Properties.cs +++ b/LabApi/Loader/Features/Plugins/Configuration/Properties.cs @@ -21,11 +21,8 @@ public class Properties public bool IsEnabled { get; set; } = true; /// - /// Whether should print logs. + /// Whether Debug logs should be printed for this plugin. /// - /// - /// Using the same naming as EXILED to ease transition for devs moving to LabAPI. - /// [Description("Whether or not [DEBUG] log messages should appear in the console. Default is false.")] public bool Debug { get; set; } = false; diff --git a/LabApi/Loader/PluginLoader.cs b/LabApi/Loader/PluginLoader.cs index 874e53ee..1aa3784c 100644 --- a/LabApi/Loader/PluginLoader.cs +++ b/LabApi/Loader/PluginLoader.cs @@ -14,8 +14,6 @@ using System.IO; using System.Linq; using System.Reflection; -using NorthwoodLib.Pools; -using Utils.NonAllocLINQ; namespace LabApi.Loader; @@ -236,7 +234,7 @@ public static void LoadPlugins(IEnumerable files) public static void EnablePlugins(IEnumerable plugins) { Logger.DebugEnabled.Clear(); - + foreach (Plugin plugin in plugins) { // We try to load the configuration of the plugin