Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b538fa
commit 055eac2
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BepInEx.Configuration; | ||
using HarmonyLogger = HarmonyLib.Tools.Logger; | ||
|
||
namespace BepInEx.Logging | ||
{ | ||
internal class HarmonyLogSource : ILogSource | ||
{ | ||
private static readonly ConfigEntry<HarmonyLogger.LogChannel> LogChannels = ConfigFile.CoreConfig.Bind( | ||
"Harmony.Logger", | ||
"LogChannels", | ||
HarmonyLogger.LogChannel.Warn | HarmonyLogger.LogChannel.Error, | ||
"Specifies which Harmony log channels to listen to.\nNOTE: IL channel dumps the whole patch methods, use only when needed!"); | ||
|
||
private static readonly Dictionary<HarmonyLogger.LogChannel, LogLevel> LevelMap = new Dictionary<HarmonyLogger.LogChannel, LogLevel> | ||
{ | ||
[HarmonyLogger.LogChannel.Info] = LogLevel.Info, | ||
[HarmonyLogger.LogChannel.Warn] = LogLevel.Warning, | ||
[HarmonyLogger.LogChannel.Error] = LogLevel.Error, | ||
[HarmonyLogger.LogChannel.IL] = LogLevel.Debug | ||
}; | ||
|
||
public HarmonyLogSource() | ||
{ | ||
HarmonyLogger.ChannelFilter = LogChannels.Value; | ||
HarmonyLogger.MessageReceived += HandleHarmonyMessage; | ||
} | ||
|
||
private void HandleHarmonyMessage(object sender, HarmonyLib.Tools.Logger.LogEventArgs e) | ||
{ | ||
if (!LevelMap.TryGetValue(e.LogChannel, out var level)) | ||
return; | ||
|
||
LogEvent?.Invoke(this, new LogEventArgs(e.Message, level, this)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
HarmonyLogger.MessageReceived -= HandleHarmonyMessage; | ||
} | ||
|
||
public string SourceName { get; } = "Harmony"; | ||
public event EventHandler<LogEventArgs> LogEvent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters