diff --git a/Dalamud/Configuration/DalamudConfiguration.cs b/Dalamud/Configuration/DalamudConfiguration.cs index b3d32e5c3..46c3381d0 100644 --- a/Dalamud/Configuration/DalamudConfiguration.cs +++ b/Dalamud/Configuration/DalamudConfiguration.cs @@ -5,6 +5,7 @@ using System.IO; using Dalamud.Game.Text; using Newtonsoft.Json; using Serilog; +using Serilog.Events; namespace Dalamud.Configuration { @@ -12,7 +13,7 @@ namespace Dalamud.Configuration /// Class containing Dalamud settings. /// [Serializable] - internal class DalamudConfiguration + public class DalamudConfiguration { [JsonIgnore] private string configPath; @@ -113,6 +114,11 @@ namespace Dalamud.Configuration /// public bool DoButtonsSystemMenu { get; set; } = true; + /// + /// Gets or sets the default Dalamud debug log level on startup. + /// + public LogEventLevel LogLevel { get; set; } = LogEventLevel.Information; + /// /// Gets or sets a value indicating whether or not the debug log should scroll automatically. /// diff --git a/Dalamud/Configuration/ThirdRepoSetting.cs b/Dalamud/Configuration/ThirdRepoSetting.cs index 63ab9f333..b0fcb03b0 100644 --- a/Dalamud/Configuration/ThirdRepoSetting.cs +++ b/Dalamud/Configuration/ThirdRepoSetting.cs @@ -3,7 +3,7 @@ namespace Dalamud.Configuration /// /// Third party repository for dalamud plugins. /// - internal class ThirdRepoSetting + public class ThirdRepoSetting { /// /// Gets or sets the third party repo url. diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 3b0638053..5453da2a6 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -43,10 +43,12 @@ namespace Dalamud /// DalamudStartInfo instance. /// LoggingLevelSwitch to control Serilog level. /// Signal signalling shutdown. - public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal) + /// The Dalamud configuration. + public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal, DalamudConfiguration configuration) { this.StartInfo = info; this.LogLevelSwitch = loggingLevelSwitch; + this.Configuration = configuration; this.baseDirectory = info.WorkingDirectory; @@ -226,8 +228,6 @@ namespace Dalamud { try { - this.Configuration = DalamudConfiguration.Load(this.StartInfo.ConfigurationPath); - this.AntiDebug = new AntiDebug(this.SigScanner); if (this.Configuration.IsAntiAntiDebugEnabled) this.AntiDebug.Enable(); diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 39fe1e38b..9287ec033 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -4,6 +4,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; +using Dalamud.Configuration; using Dalamud.Interface; using EasyHook; using Serilog; @@ -34,8 +35,11 @@ namespace Dalamud /// The containing information needed to initialize Dalamud. public void Run(RemoteHooking.IContext ctx, DalamudStartInfo info) { + // Load configuration first to get some early persistent state, like log level + var configuration = DalamudConfiguration.Load(info.ConfigurationPath); + // Setup logger - var (logger, levelSwitch) = this.NewLogger(info.WorkingDirectory); + var (logger, levelSwitch) = this.NewLogger(info.WorkingDirectory, configuration.LogLevel); Log.Logger = logger; var finishSignal = new ManualResetEvent(false); @@ -53,7 +57,7 @@ namespace Dalamud AppDomain.CurrentDomain.UnhandledException += this.OnUnhandledException; TaskScheduler.UnobservedTaskException += this.OnUnobservedTaskException; - var dalamud = new Dalamud(info, levelSwitch, finishSignal); + var dalamud = new Dalamud(info, levelSwitch, finishSignal, configuration); Log.Information("Starting a session.."); // Run session @@ -77,7 +81,7 @@ namespace Dalamud } } - private (Logger Logger, LoggingLevelSwitch LevelSwitch) NewLogger(string baseDirectory) + private (Logger Logger, LoggingLevelSwitch LevelSwitch) NewLogger(string baseDirectory, LogEventLevel logLevel) { #if DEBUG var logPath = Path.Combine(baseDirectory, "dalamud.log"); @@ -90,7 +94,7 @@ namespace Dalamud #if DEBUG levelSwitch.MinimumLevel = LogEventLevel.Verbose; #else - levelSwitch.MinimumLevel = LogEventLevel.Information; + levelSwitch.MinimumLevel = logLevel; #endif var newLogger = new LoggerConfiguration() diff --git a/Dalamud/Interface/DalamudInterface.cs b/Dalamud/Interface/DalamudInterface.cs index 8ac21a29a..09c15051a 100644 --- a/Dalamud/Interface/DalamudInterface.cs +++ b/Dalamud/Interface/DalamudInterface.cs @@ -190,6 +190,8 @@ namespace Dalamud.Interface if (ImGui.MenuItem(logLevel + "##logLevelSwitch", string.Empty, this.dalamud.LogLevelSwitch.MinimumLevel == logLevel)) { this.dalamud.LogLevelSwitch.MinimumLevel = logLevel; + this.dalamud.Configuration.LogLevel = logLevel; + this.dalamud.Configuration.Save(); } }