diff --git a/LabApi/Features/Console/Logger.cs b/LabApi/Features/Console/Logger.cs
index e0c59c16..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;
@@ -22,12 +23,25 @@ public static class Logger
/// The color of the message.
public static void Raw(string message, ConsoleColor color) => ServerConsole.AddLog(message, color);
+ ///
+ /// List of assemblies to display Debug level logs for.
+ ///
+ public static HashSet DebugEnabled { get; } = new();
+
+ ///
+ /// Logs a debug message to the server console.
+ ///
+ /// 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)
+ 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..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,7 +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 0e13acf9..7910335c 100644
--- a/LabApi/Loader/Features/Plugins/Configuration/Properties.cs
+++ b/LabApi/Loader/Features/Plugins/Configuration/Properties.cs
@@ -20,6 +20,12 @@ public class Properties
[Description("Whether or not the plugin is enabled.")]
public bool IsEnabled { get; set; } = true;
+ ///
+ /// Whether Debug logs should be printed for this plugin.
+ ///
+ [Description("Whether or not [DEBUG] log messages should appear in the console. 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..1aa3784c 100644
--- a/LabApi/Loader/PluginLoader.cs
+++ b/LabApi/Loader/PluginLoader.cs
@@ -233,6 +233,8 @@ public static void LoadPlugins(IEnumerable files)
/// The sorted collection of s.
public static void EnablePlugins(IEnumerable plugins)
{
+ Logger.DebugEnabled.Clear();
+
foreach (Plugin plugin in plugins)
{
// We try to load the configuration of the plugin
@@ -253,6 +255,20 @@ 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))
+ {
+ 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);
}