feat: Allow /xldev to disable Safe Mode (#2166)

- Adds new menu item to /xldev to disable Safe Mode, allowing users to load plugins again.
  - Safe mode cannot be re-enabled once disabled.
- Add new ModuleLog.Create<T> for eventual ILogger magic
- Make safe mode writable
- Remove redundant check in CheckPolicy
This commit is contained in:
KazWolfe 2025-01-09 13:01:46 -08:00 committed by GitHub
parent da8be03124
commit a656fefb2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 13 deletions

View file

@ -1,5 +1,6 @@
using Serilog;
using Serilog.Core;
using Serilog.Core.Enrichers;
using Serilog.Events;
namespace Dalamud.Logging.Internal;
@ -11,7 +12,7 @@ public class ModuleLog
{
private readonly string moduleName;
private readonly ILogger moduleLogger;
// FIXME (v9): Deprecate this class in favor of using contextualized ILoggers with proper formatting.
// We can keep this class around as a Serilog helper, but ModuleLog should no longer be a returned
// type, instead returning a (prepared) ILogger appropriately.
@ -27,6 +28,28 @@ public class ModuleLog
this.moduleLogger = Log.ForContext("Dalamud.ModuleName", this.moduleName);
}
/// <summary>
/// Initializes a new instance of the <see cref="ModuleLog"/> class.
/// This class will properly attach SourceContext and other attributes per Serilog standards.
/// </summary>
/// <param name="type">The type of the class this logger is for.</param>
public ModuleLog(Type type)
{
this.moduleName = type.Name;
this.moduleLogger = Log.ForContext(
[
new PropertyEnricher(Constants.SourceContextPropertyName, type.FullName),
new PropertyEnricher("Dalamud.ModuleName", this.moduleName)
]);
}
/// <summary>
/// Helper method to create a new <see cref="ModuleLog"/> instance based on a type.
/// </summary>
/// <typeparam name="T">The class to create this ModuleLog for.</typeparam>
/// <returns>Returns a ModuleLog with name set.</returns>
internal static ModuleLog Create<T>() => new(typeof(T));
/// <summary>
/// Log a templated verbose message to the in-game debug log.
/// </summary>