feat: add "--console" arg to show boot console, write Dalamud logs to console if set

This commit is contained in:
goaaats 2022-06-20 15:29:49 +02:00
parent 8cc34ea1b6
commit c3e16ad92c
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 16 additions and 8 deletions

View file

@ -83,6 +83,7 @@ namespace Dalamud.Injector
}
startInfo = ExtractAndInitializeStartInfoFromArguments(startInfo, args);
args.Remove("--console"); // Remove "console" flag
var mainCommand = args[1].ToLowerInvariant();
if (mainCommand.Length > 0 && mainCommand.Length <= 6 && "inject"[..mainCommand.Length] == mainCommand)
@ -319,6 +320,7 @@ namespace Dalamud.Injector
startInfo.GameVersion = null;
// Set boot defaults
startInfo.BootShowConsole = args.Contains("--console");
startInfo.BootLogPath = GetLogPath("dalamud.boot");
startInfo.BootEnabledGameFixes = new List<string> { "prevent_devicechange_crashes", "disable_game_openprocess_access_check", "redirect_openprocess" };
startInfo.BootDotnetOpenProcessHookMode = 0;
@ -356,7 +358,8 @@ namespace Dalamud.Injector
Console.WriteLine(" [--dalamud-asset-directory=path] [--dalamud-delay-initialize=0(ms)]");
Console.WriteLine(" [--dalamud-client-language=0-3|j(apanese)|e(nglish)|d|g(erman)|f(rench)]");
Console.WriteLine("Verbose logging: [-v]");
Console.WriteLine("Verbose logging:\t[-v]");
Console.WriteLine("Show Console:\t[--console]");
return 0;
}

View file

@ -72,6 +72,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Reloaded.Hooks" Version="3.5.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">

View file

@ -112,7 +112,7 @@ namespace Dalamud
private static void RunThread(DalamudStartInfo info, IntPtr mainThreadContinueEvent)
{
// Setup logger
var levelSwitch = InitLogging(info.WorkingDirectory);
var levelSwitch = InitLogging(info.WorkingDirectory, info.BootShowConsole);
// Load configuration first to get some early persistent state, like log level
var configuration = DalamudConfiguration.Load(info.ConfigurationPath);
@ -193,7 +193,7 @@ namespace Dalamud
}
}
private static LoggingLevelSwitch InitLogging(string baseDirectory)
private static LoggingLevelSwitch InitLogging(string baseDirectory, bool logConsole)
{
#if DEBUG
var logPath = Path.Combine(baseDirectory, "dalamud.log");
@ -207,11 +207,15 @@ namespace Dalamud
CullLogFile(oldPath, null, 10 * 1024 * 1024);
var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Verbose);
Log.Logger = new LoggerConfiguration()
.WriteTo.Async(a => a.File(logPath, fileSizeLimitBytes: null, buffered: false, flushToDiskInterval: TimeSpan.FromSeconds(1)))
.WriteTo.Sink(SerilogEventSink.Instance)
.MinimumLevel.ControlledBy(levelSwitch)
.CreateLogger();
var config = new LoggerConfiguration()
.WriteTo.Async(a => a.File(logPath, fileSizeLimitBytes: null, buffered: false, flushToDiskInterval: TimeSpan.FromSeconds(1)))
.WriteTo.Sink(SerilogEventSink.Instance)
.MinimumLevel.ControlledBy(levelSwitch);
if (logConsole)
config = config.WriteTo.Console();
Log.Logger = config.CreateLogger();
return levelSwitch;
}