feat: configurable log path

This commit is contained in:
goat 2023-01-11 18:37:33 +01:00
parent 4264db8d67
commit cc4a0652c2
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
6 changed files with 40 additions and 23 deletions

View file

@ -28,7 +28,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Lumina" Version="3.10.0" /> <PackageReference Include="Lumina" Version="3.10.0" />
<PackageReference Include="Lumina.Excel" Version="6.2.1" /> <PackageReference Include="Lumina.Excel" Version="6.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333"> <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

View file

@ -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); var baseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
fileName = !string.IsNullOrEmpty(logName) ? $"{fileName}-{logName}.log" : $"{fileName}.log";
#if DEBUG #if DEBUG
var logPath = Path.Combine(baseDirectory, $"{filename}.log"); var logPath = Path.Combine(baseDirectory, fileName);
#else #else
var logPath = Path.Combine(baseDirectory, "..", "..", "..", $"{filename}.log"); var logPath = Path.Combine(baseDirectory, "..", "..", "..", fileName);
#endif #endif
return logPath; return logPath;
@ -130,7 +131,7 @@ namespace Dalamud.Injector
private static void Init(List<string> args) private static void Init(List<string> args)
{ {
InitLogging(args.Any(x => x == "-v")); InitLogging(args.Any(x => x == "-v"), args);
InitUnhandledException(args); InitUnhandledException(args);
var cwd = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory; 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<string> args)
{ {
#if DEBUG #if DEBUG
verbose = true; verbose = true;
@ -182,7 +183,8 @@ namespace Dalamud.Injector
MinimumLevel = verbose ? LogEventLevel.Verbose : LogEventLevel.Information, 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); CullLogFile(logPath, 1 * 1024 * 1024);
@ -252,11 +254,13 @@ namespace Dalamud.Injector
var defaultPluginDirectory = startInfo.DefaultPluginDirectory; var defaultPluginDirectory = startInfo.DefaultPluginDirectory;
var assetDirectory = startInfo.AssetDirectory; var assetDirectory = startInfo.AssetDirectory;
var delayInitializeMs = startInfo.DelayInitializeMs; var delayInitializeMs = startInfo.DelayInitializeMs;
var logName = startInfo.LogName;
var languageStr = startInfo.Language.ToString().ToLowerInvariant(); var languageStr = startInfo.Language.ToString().ToLowerInvariant();
var troubleshootingData = "{\"empty\": true, \"description\": \"No troubleshooting data supplied.\"}"; var troubleshootingData = "{\"empty\": true, \"description\": \"No troubleshooting data supplied.\"}";
for (var i = 2; i < args.Count; i++) for (var i = 2; i < args.Count; i++)
{ {
Log.Information(args[i]);
if (args[i].StartsWith(key = "--dalamud-working-directory=")) if (args[i].StartsWith(key = "--dalamud-working-directory="))
workingDirectory = args[i][key.Length..]; workingDirectory = args[i][key.Length..];
else if (args[i].StartsWith(key = "--dalamud-configuration-path=")) else if (args[i].StartsWith(key = "--dalamud-configuration-path="))
@ -273,6 +277,8 @@ namespace Dalamud.Injector
languageStr = args[i][key.Length..].ToLowerInvariant(); languageStr = args[i][key.Length..].ToLowerInvariant();
else if (args[i].StartsWith(key = "--dalamud-tspack-b64=")) else if (args[i].StartsWith(key = "--dalamud-tspack-b64="))
troubleshootingData = Encoding.UTF8.GetString(Convert.FromBase64String(args[i][key.Length..])); troubleshootingData = Encoding.UTF8.GetString(Convert.FromBase64String(args[i][key.Length..]));
else if (args[i].StartsWith(key = "--logname="))
logName = args[i][key.Length..];
else else
continue; continue;
@ -318,11 +324,12 @@ namespace Dalamud.Injector
startInfo.DelayInitializeMs = delayInitializeMs; startInfo.DelayInitializeMs = delayInitializeMs;
startInfo.GameVersion = null; startInfo.GameVersion = null;
startInfo.TroubleshootingPackData = troubleshootingData; startInfo.TroubleshootingPackData = troubleshootingData;
startInfo.LogName = logName;
// Set boot defaults // Set boot defaults
startInfo.BootShowConsole = args.Contains("--console"); startInfo.BootShowConsole = args.Contains("--console");
startInfo.BootEnableEtw = args.Contains("--etw"); startInfo.BootEnableEtw = args.Contains("--etw");
startInfo.BootLogPath = GetLogPath("dalamud.boot"); startInfo.BootLogPath = GetLogPath("dalamud.boot", startInfo.LogName);
startInfo.BootEnabledGameFixes = new List<string> { "prevent_devicechange_crashes", "disable_game_openprocess_access_check", "redirect_openprocess", "backup_userdata_save", "clr_failfast_hijack" }; startInfo.BootEnabledGameFixes = new List<string> { "prevent_devicechange_crashes", "disable_game_openprocess_access_check", "redirect_openprocess", "backup_userdata_save", "clr_failfast_hijack" };
startInfo.BootDotnetOpenProcessHookMode = 0; startInfo.BootDotnetOpenProcessHookMode = 0;
startInfo.BootWaitMessageBox |= args.Contains("--msgbox1") ? 1 : 0; startInfo.BootWaitMessageBox |= args.Contains("--msgbox1") ? 1 : 0;

View file

@ -28,6 +28,7 @@ public record DalamudStartInfo : IServiceType
{ {
this.WorkingDirectory = other.WorkingDirectory; this.WorkingDirectory = other.WorkingDirectory;
this.ConfigurationPath = other.ConfigurationPath; this.ConfigurationPath = other.ConfigurationPath;
this.LogName = other.LogName;
this.PluginDirectory = other.PluginDirectory; this.PluginDirectory = other.PluginDirectory;
this.DefaultPluginDirectory = other.DefaultPluginDirectory; this.DefaultPluginDirectory = other.DefaultPluginDirectory;
this.AssetDirectory = other.AssetDirectory; this.AssetDirectory = other.AssetDirectory;
@ -61,6 +62,11 @@ public record DalamudStartInfo : IServiceType
/// </summary> /// </summary>
public string? ConfigurationPath { get; set; } public string? ConfigurationPath { get; set; }
/// <summary>
/// Gets or sets the name of the log file.
/// </summary>
public string? LogName { get; set; }
/// <summary> /// <summary>
/// Gets or sets the path to the directory for installed plugins. /// Gets or sets the path to the directory for installed plugins.
/// </summary> /// </summary>

View file

@ -81,16 +81,19 @@ public sealed class EntryPoint
/// <param name="baseDirectory">Base directory.</param> /// <param name="baseDirectory">Base directory.</param>
/// <param name="logConsole">Whether to log to console.</param> /// <param name="logConsole">Whether to log to console.</param>
/// <param name="logSynchronously">Log synchronously.</param> /// <param name="logSynchronously">Log synchronously.</param>
internal static void InitLogging(string baseDirectory, bool logConsole, bool logSynchronously) /// <param name="logName">Name that should be appended to the log file.</param>
internal static void InitLogging(string baseDirectory, bool logConsole, bool logSynchronously, string? logName)
{ {
var logFileName = logName.IsNullOrEmpty() ? "dalamud" : $"dalamud-{logName}";
#if DEBUG #if DEBUG
var logPath = Path.Combine(baseDirectory, "dalamud.log"); var logPath = Path.Combine(baseDirectory, $"{logFileName}.log");
var oldPath = Path.Combine(baseDirectory, "dalamud.old.log"); var oldPath = Path.Combine(baseDirectory, $"{logFileName}.old.log");
var oldPathOld = Path.Combine(baseDirectory, "dalamud.log.old"); var oldPathOld = Path.Combine(baseDirectory, $"{logFileName}.log.old");
#else #else
var logPath = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.log"); var logPath = Path.Combine(baseDirectory, "..", "..", "..", $"{logFileName}.log");
var oldPath = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.old.log"); var oldPath = Path.Combine(baseDirectory, "..", "..", "..", $"{logFileName}.old.log");
var oldPathOld = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.log.old"); var oldPathOld = Path.Combine(baseDirectory, "..", "..", "..", $"{logFileName}.log.old");
#endif #endif
Log.CloseAndFlush(); Log.CloseAndFlush();
@ -137,7 +140,7 @@ public sealed class EntryPoint
private static void RunThread(DalamudStartInfo info, IntPtr mainThreadContinueEvent) private static void RunThread(DalamudStartInfo info, IntPtr mainThreadContinueEvent)
{ {
// Setup logger // Setup logger
InitLogging(info.WorkingDirectory!, info.BootShowConsole, true); InitLogging(info.WorkingDirectory!, info.BootShowConsole, true, info.LogName);
SerilogEventSink.Instance.LogLine += SerilogOnLogLine; SerilogEventSink.Instance.LogLine += SerilogOnLogLine;
// Load configuration first to get some early persistent state, like log level // Load configuration first to get some early persistent state, like log level

View file

@ -571,17 +571,19 @@ internal class DalamudInterface : IDisposable, IServiceType
ImGui.EndMenu(); ImGui.EndMenu();
} }
var startInfo = Service<DalamudStartInfo>.Get();
var logSynchronously = configuration.LogSynchronously; var logSynchronously = configuration.LogSynchronously;
if (ImGui.MenuItem("Log Synchronously", null, ref logSynchronously)) if (ImGui.MenuItem("Log Synchronously", null, ref logSynchronously))
{ {
configuration.LogSynchronously = logSynchronously; configuration.LogSynchronously = logSynchronously;
configuration.QueueSave(); configuration.QueueSave();
var startupInfo = Service<DalamudStartInfo>.Get();
EntryPoint.InitLogging( EntryPoint.InitLogging(
startupInfo.WorkingDirectory!, startInfo.WorkingDirectory!,
startupInfo.BootShowConsole, startInfo.BootShowConsole,
configuration.LogSynchronously); configuration.LogSynchronously,
startInfo.LogName);
} }
var antiDebug = Service<AntiDebug>.Get(); var antiDebug = Service<AntiDebug>.Get();
@ -693,9 +695,8 @@ internal class DalamudInterface : IDisposable, IServiceType
this.OpenBranchSwitcher(); this.OpenBranchSwitcher();
} }
var startInfo = Service<DalamudStartInfo>.Get();
ImGui.MenuItem(Util.AssemblyVersion, false); 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($"D: {Util.GetGitHash()} CS: {Util.GetGitHashClientStructs()}", false);
ImGui.MenuItem($"CLR: {Environment.Version}", false); ImGui.MenuItem($"CLR: {Environment.Version}", false);

@ -1 +1 @@
Subproject commit e166ae024d04dc18b115405c8788cbcaf8d4c0f0 Subproject commit 34a302e0837787917c3a58cec79cecf1e2875e7a