diff --git a/Dalamud.CorePlugin/Dalamud.CorePlugin.csproj b/Dalamud.CorePlugin/Dalamud.CorePlugin.csproj index d93f4bf25..655e4bd74 100644 --- a/Dalamud.CorePlugin/Dalamud.CorePlugin.csproj +++ b/Dalamud.CorePlugin/Dalamud.CorePlugin.csproj @@ -28,7 +28,7 @@ - + all diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index d1ada5f64..a7dca9392 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -115,14 +115,15 @@ namespace Dalamud.Injector } } - private static string GetLogPath(string filename) + private static string GetLogPath(string fileName, string logName) { var baseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + fileName = !string.IsNullOrEmpty(logName) ? $"{fileName}-{logName}.log" : $"{fileName}.log"; #if DEBUG - var logPath = Path.Combine(baseDirectory, $"{filename}.log"); + var logPath = Path.Combine(baseDirectory, fileName); #else - var logPath = Path.Combine(baseDirectory, "..", "..", "..", $"{filename}.log"); + var logPath = Path.Combine(baseDirectory, "..", "..", "..", fileName); #endif return logPath; @@ -130,7 +131,7 @@ namespace Dalamud.Injector private static void Init(List args) { - InitLogging(args.Any(x => x == "-v")); + InitLogging(args.Any(x => x == "-v"), args); InitUnhandledException(args); var cwd = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory; @@ -171,7 +172,7 @@ namespace Dalamud.Injector }; } - private static void InitLogging(bool verbose) + private static void InitLogging(bool verbose, IEnumerable args) { #if DEBUG verbose = true; @@ -182,7 +183,8 @@ namespace Dalamud.Injector MinimumLevel = verbose ? LogEventLevel.Verbose : LogEventLevel.Information, }; - var logPath = GetLogPath("dalamud.injector"); + var logName = args.FirstOrDefault(x => x.StartsWith("--logname="))?[10..]; + var logPath = GetLogPath("dalamud.injector", logName); CullLogFile(logPath, 1 * 1024 * 1024); @@ -252,11 +254,13 @@ namespace Dalamud.Injector var defaultPluginDirectory = startInfo.DefaultPluginDirectory; var assetDirectory = startInfo.AssetDirectory; var delayInitializeMs = startInfo.DelayInitializeMs; + var logName = startInfo.LogName; var languageStr = startInfo.Language.ToString().ToLowerInvariant(); var troubleshootingData = "{\"empty\": true, \"description\": \"No troubleshooting data supplied.\"}"; for (var i = 2; i < args.Count; i++) { + Log.Information(args[i]); if (args[i].StartsWith(key = "--dalamud-working-directory=")) workingDirectory = args[i][key.Length..]; else if (args[i].StartsWith(key = "--dalamud-configuration-path=")) @@ -273,6 +277,8 @@ namespace Dalamud.Injector languageStr = args[i][key.Length..].ToLowerInvariant(); else if (args[i].StartsWith(key = "--dalamud-tspack-b64=")) troubleshootingData = Encoding.UTF8.GetString(Convert.FromBase64String(args[i][key.Length..])); + else if (args[i].StartsWith(key = "--logname=")) + logName = args[i][key.Length..]; else continue; @@ -318,11 +324,12 @@ namespace Dalamud.Injector startInfo.DelayInitializeMs = delayInitializeMs; startInfo.GameVersion = null; startInfo.TroubleshootingPackData = troubleshootingData; + startInfo.LogName = logName; // Set boot defaults startInfo.BootShowConsole = args.Contains("--console"); startInfo.BootEnableEtw = args.Contains("--etw"); - startInfo.BootLogPath = GetLogPath("dalamud.boot"); + startInfo.BootLogPath = GetLogPath("dalamud.boot", startInfo.LogName); startInfo.BootEnabledGameFixes = new List { "prevent_devicechange_crashes", "disable_game_openprocess_access_check", "redirect_openprocess", "backup_userdata_save", "clr_failfast_hijack" }; startInfo.BootDotnetOpenProcessHookMode = 0; startInfo.BootWaitMessageBox |= args.Contains("--msgbox1") ? 1 : 0; diff --git a/Dalamud/DalamudStartInfo.cs b/Dalamud/DalamudStartInfo.cs index 0010741bf..658934005 100644 --- a/Dalamud/DalamudStartInfo.cs +++ b/Dalamud/DalamudStartInfo.cs @@ -28,6 +28,7 @@ public record DalamudStartInfo : IServiceType { this.WorkingDirectory = other.WorkingDirectory; this.ConfigurationPath = other.ConfigurationPath; + this.LogName = other.LogName; this.PluginDirectory = other.PluginDirectory; this.DefaultPluginDirectory = other.DefaultPluginDirectory; this.AssetDirectory = other.AssetDirectory; @@ -61,6 +62,11 @@ public record DalamudStartInfo : IServiceType /// public string? ConfigurationPath { get; set; } + /// + /// Gets or sets the name of the log file. + /// + public string? LogName { get; set; } + /// /// Gets or sets the path to the directory for installed plugins. /// diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 35579c5dc..221c6ce67 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -81,16 +81,19 @@ public sealed class EntryPoint /// Base directory. /// Whether to log to console. /// Log synchronously. - internal static void InitLogging(string baseDirectory, bool logConsole, bool logSynchronously) + /// Name that should be appended to the log file. + internal static void InitLogging(string baseDirectory, bool logConsole, bool logSynchronously, string? logName) { + var logFileName = logName.IsNullOrEmpty() ? "dalamud" : $"dalamud-{logName}"; + #if DEBUG - var logPath = Path.Combine(baseDirectory, "dalamud.log"); - var oldPath = Path.Combine(baseDirectory, "dalamud.old.log"); - var oldPathOld = Path.Combine(baseDirectory, "dalamud.log.old"); + var logPath = Path.Combine(baseDirectory, $"{logFileName}.log"); + var oldPath = Path.Combine(baseDirectory, $"{logFileName}.old.log"); + var oldPathOld = Path.Combine(baseDirectory, $"{logFileName}.log.old"); #else - var logPath = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.log"); - var oldPath = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.old.log"); - var oldPathOld = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.log.old"); + var logPath = Path.Combine(baseDirectory, "..", "..", "..", $"{logFileName}.log"); + var oldPath = Path.Combine(baseDirectory, "..", "..", "..", $"{logFileName}.old.log"); + var oldPathOld = Path.Combine(baseDirectory, "..", "..", "..", $"{logFileName}.log.old"); #endif Log.CloseAndFlush(); @@ -137,7 +140,7 @@ public sealed class EntryPoint private static void RunThread(DalamudStartInfo info, IntPtr mainThreadContinueEvent) { // Setup logger - InitLogging(info.WorkingDirectory!, info.BootShowConsole, true); + InitLogging(info.WorkingDirectory!, info.BootShowConsole, true, info.LogName); SerilogEventSink.Instance.LogLine += SerilogOnLogLine; // Load configuration first to get some early persistent state, like log level diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 14d8f10de..97313730f 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -571,17 +571,19 @@ internal class DalamudInterface : IDisposable, IServiceType ImGui.EndMenu(); } + var startInfo = Service.Get(); + var logSynchronously = configuration.LogSynchronously; if (ImGui.MenuItem("Log Synchronously", null, ref logSynchronously)) { configuration.LogSynchronously = logSynchronously; configuration.QueueSave(); - var startupInfo = Service.Get(); EntryPoint.InitLogging( - startupInfo.WorkingDirectory!, - startupInfo.BootShowConsole, - configuration.LogSynchronously); + startInfo.WorkingDirectory!, + startInfo.BootShowConsole, + configuration.LogSynchronously, + startInfo.LogName); } var antiDebug = Service.Get(); @@ -693,9 +695,8 @@ internal class DalamudInterface : IDisposable, IServiceType this.OpenBranchSwitcher(); } - var startInfo = Service.Get(); ImGui.MenuItem(Util.AssemblyVersion, false); - ImGui.MenuItem(startInfo.GameVersion.ToString(), false); + ImGui.MenuItem(startInfo.GameVersion?.ToString() ?? "Unknown version", false); ImGui.MenuItem($"D: {Util.GetGitHash()} CS: {Util.GetGitHashClientStructs()}", false); ImGui.MenuItem($"CLR: {Environment.Version}", false); diff --git a/lib/FFXIVClientStructs b/lib/FFXIVClientStructs index e166ae024..34a302e08 160000 --- a/lib/FFXIVClientStructs +++ b/lib/FFXIVClientStructs @@ -1 +1 @@ -Subproject commit e166ae024d04dc18b115405c8788cbcaf8d4c0f0 +Subproject commit 34a302e0837787917c3a58cec79cecf1e2875e7a