Browse Source

Adjust log level mappings for Harmony logs

pull/74/head
Anairkoen Schno 2 years ago
parent
commit
0eaa9e8ef3
Signed by: DaNike GPG Key ID: BEFB74D5F3FC4387
2 changed files with 10 additions and 5 deletions
  1. +1
    -1
      IPA.Injector/Injector.cs
  2. +9
    -4
      IPA.Loader/Logging/StdoutInterceptor.cs

+ 1
- 1
IPA.Injector/Injector.cs View File

@ -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();


+ 9
- 4
IPA.Loader/Logging/StdoutInterceptor.cs View File

@ -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,


Loading…
Cancel
Save