Merge pull request #389 from Philpax/persistent-log-level

This commit is contained in:
goaaats 2021-07-11 21:08:31 +02:00 committed by GitHub
commit 78f56480ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 9 deletions

View file

@ -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.
/// </summary>
[Serializable]
internal class DalamudConfiguration
public class DalamudConfiguration
{
[JsonIgnore]
private string configPath;
@ -113,6 +114,11 @@ namespace Dalamud.Configuration
/// </summary>
public bool DoButtonsSystemMenu { get; set; } = true;
/// <summary>
/// Gets or sets the default Dalamud debug log level on startup.
/// </summary>
public LogEventLevel LogLevel { get; set; } = LogEventLevel.Information;
/// <summary>
/// Gets or sets a value indicating whether or not the debug log should scroll automatically.
/// </summary>

View file

@ -3,7 +3,7 @@ namespace Dalamud.Configuration
/// <summary>
/// Third party repository for dalamud plugins.
/// </summary>
internal class ThirdRepoSetting
public class ThirdRepoSetting
{
/// <summary>
/// Gets or sets the third party repo url.

View file

@ -43,10 +43,12 @@ namespace Dalamud
/// <param name="info">DalamudStartInfo instance.</param>
/// <param name="loggingLevelSwitch">LoggingLevelSwitch to control Serilog level.</param>
/// <param name="finishSignal">Signal signalling shutdown.</param>
public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal)
/// <param name="configuration">The Dalamud configuration.</param>
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();

View file

@ -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
/// <param name="info">The <see cref="DalamudStartInfo"/> containing information needed to initialize Dalamud.</param>
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()

View file

@ -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();
}
}