From 0eaa9e8ef33b1c8e56b5d50c372bd6e695202207 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 15 Dec 2021 16:27:01 -0600 Subject: [PATCH] Adjust log level mappings for Harmony logs --- IPA.Injector/Injector.cs | 2 +- IPA.Loader/Logging/StdoutInterceptor.cs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 523e869c..acfbe4a2 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -312,7 +312,7 @@ namespace IPA.Injector UnityLogProvider.UnityLogger.Log(level, $"{stackTrace}"); }; - ConfigureHarmonyLogging(); + StdoutInterceptor.EnsureHarmonyLogging(); // need to reinit streams singe Unity seems to redirect stdout StdoutInterceptor.RedirectConsole(); diff --git a/IPA.Loader/Logging/StdoutInterceptor.cs b/IPA.Loader/Logging/StdoutInterceptor.cs index 9d83851c..26d14fe9 100644 --- a/IPA.Loader/Logging/StdoutInterceptor.cs +++ b/IPA.Loader/Logging/StdoutInterceptor.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Reflection.Emit; using System.Text; +using System.Threading; using static IPA.Logging.Logger; namespace IPA.Logging @@ -189,7 +190,7 @@ namespace IPA.Logging { usingInterceptor = true; - ConfigureHarmonyLogging(); + EnsureHarmonyLogging(); harmony ??= new Harmony("BSIPA Console Redirector Patcher"); stdoutInterceptor ??= new StdoutInterceptor(); @@ -209,17 +210,21 @@ namespace IPA.Logging } } + private static int harmonyLoggingInited; // I'm not completely sure this is the best place for this, but whatever - private static void ConfigureHarmonyLogging() + internal static void EnsureHarmonyLogging() { + if (Interlocked.Exchange(ref harmonyLoggingInited, 1) != 0) + return; + HarmonyLib.Tools.Logger.ChannelFilter = HarmonyLib.Tools.Logger.LogChannel.All & ~HarmonyLib.Tools.Logger.LogChannel.IL; HarmonyLib.Tools.Logger.MessageReceived += (s, e) => { var msg = e.Message; var lvl = e.LogChannel switch { - HarmonyLib.Tools.Logger.LogChannel.None => Level.Info, - HarmonyLib.Tools.Logger.LogChannel.Info => Level.Info, + HarmonyLib.Tools.Logger.LogChannel.None => Level.Notice, + HarmonyLib.Tools.Logger.LogChannel.Info => Level.Trace, // HarmonyX logs a *lot* of Info messages HarmonyLib.Tools.Logger.LogChannel.IL => Level.Trace, HarmonyLib.Tools.Logger.LogChannel.Warn => Level.Warning, HarmonyLib.Tools.Logger.LogChannel.Error => Level.Error,