From ad28b302f9acf0edbc7bdc5e0e4253b65c09dbbe Mon Sep 17 00:00:00 2001
From: zznty <94796179+zznty@users.noreply.github.com>
Date: Sat, 15 Oct 2022 00:42:23 +0700
Subject: [PATCH] add harmony logging
---
Torch/TorchBase.cs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs
index f7fb909..6b14832 100644
--- a/Torch/TorchBase.cs
+++ b/Torch/TorchBase.cs
@@ -92,6 +92,7 @@ namespace Torch
///
///
///
+ ///
/// Thrown if a TorchBase instance already exists.
protected TorchBase(ITorchConfig config)
{
@@ -147,6 +148,20 @@ namespace Torch
PatchManager.CommitInternal();
}
};
+
+ var harmonyLog = LogManager.GetLogger("HarmonyX");
+ HarmonyLib.Tools.Logger.ChannelFilter = HarmonyLib.Tools.Logger.LogChannel.Debug;
+ HarmonyLib.Tools.Logger.MessageReceived += (_, args) => harmonyLog.Log(args.LogChannel switch
+ {
+ HarmonyLib.Tools.Logger.LogChannel.None => LogLevel.Off,
+ HarmonyLib.Tools.Logger.LogChannel.Info => LogLevel.Info,
+ HarmonyLib.Tools.Logger.LogChannel.IL => LogLevel.Trace,
+ HarmonyLib.Tools.Logger.LogChannel.Warn => LogLevel.Warn,
+ HarmonyLib.Tools.Logger.LogChannel.Error => LogLevel.Error,
+ HarmonyLib.Tools.Logger.LogChannel.Debug => LogLevel.Debug,
+ HarmonyLib.Tools.Logger.LogChannel.All => LogLevel.Debug,
+ _ => throw new ArgumentOutOfRangeException()
+ }, args.Message);
}
[Obsolete("Prefer using Managers.GetManager for global managers")]