From c3e16ad92cd6c731ee31ae71c217e2dd3790f84b Mon Sep 17 00:00:00 2001 From: goaaats Date: Mon, 20 Jun 2022 15:29:49 +0200 Subject: [PATCH] feat: add "--console" arg to show boot console, write Dalamud logs to console if set --- Dalamud.Injector/EntryPoint.cs | 5 ++++- Dalamud/Dalamud.csproj | 1 + Dalamud/EntryPoint.cs | 18 +++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index 9a10eece0..1539a18e0 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -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 { "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; } diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index ebc227ef6..ebd182fd5 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -72,6 +72,7 @@ + diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index c02557741..394fb4908 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -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; }