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>
<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="StyleCop.Analyzers" Version="1.2.0-beta.333">
<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);
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<string> 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<string> 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<string> { "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;

View file

@ -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
/// </summary>
public string? ConfigurationPath { get; set; }
/// <summary>
/// Gets or sets the name of the log file.
/// </summary>
public string? LogName { get; set; }
/// <summary>
/// Gets or sets the path to the directory for installed plugins.
/// </summary>

View file

@ -81,16 +81,19 @@ public sealed class EntryPoint
/// <param name="baseDirectory">Base directory.</param>
/// <param name="logConsole">Whether to log to console.</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
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

View file

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

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