1
0
Fork 0

Deduplicate logs to avoid spamming console with errors each frame

This commit is contained in:
ivan tkachenko 2026-01-18 16:22:05 +02:00
parent a254188f0c
commit a2cf66476c
2 changed files with 83 additions and 5 deletions

View File

@ -0,0 +1,70 @@
using BepInEx.Logging;
namespace MuzikaGromche;
#if DEBUG
// A logger with an API similar to ManualLogSource.
// This logger caches last posted messagee and uses it to deduplicate subsequent messages.
// Use Clear() to forget deduplicated message.
internal class DedupManualLogSource
{
public ManualLogSource Source;
object? lastData = null;
public DedupManualLogSource(ManualLogSource source)
{
Source = source;
}
public void Log(LogLevel level, object data)
{
if (lastData != data)
{
lastData = data;
Source.Log(level, data);
}
}
public void LogFatal(object data)
{
Log(LogLevel.Fatal, data);
}
public void LogError(object data)
{
Log(LogLevel.Error, data);
}
public void LogWarning(object data)
{
Log(LogLevel.Warning, data);
}
public void LogMessage(object data)
{
Log(LogLevel.Message, data);
}
public void LogInfo(object data)
{
Log(LogLevel.Info, data);
}
public void LogDebug(object data)
{
Log(LogLevel.Debug, data);
}
public void Clear()
{
lastData = null;
}
public void Dispose()
{
}
}
#endif

View File

@ -1178,6 +1178,7 @@ namespace MuzikaGromche
Array.Sort(Tracks.Select(track => track.Name).ToArray(), Tracks);
#if DEBUG
JesterPatch.DedupLog = new DedupManualLogSource(Logger);
GlobalBehaviour.Instance.StartCoroutine(PreloadDebugAndExport(Tracks));
#endif
Config = new Config(base.Config);
@ -3319,6 +3320,11 @@ namespace MuzikaGromche
};
}
#if DEBUG
// avoid spamming console with errors each frame
public static DedupManualLogSource DedupLog = null!;
#endif
[HarmonyPatch(nameof(JesterAI.Update))]
[HarmonyPostfix]
static void JesterUpdatePostfix(JesterAI __instance, State __state)
@ -3331,21 +3337,23 @@ namespace MuzikaGromche
{
#if DEBUG
if (behaviour.CurrentTrack == null)
{
Plugin.Log.LogError("CurrentTrack is not set!");
{
DedupLog.LogWarning("CurrentTrack is not set!");
}
else if (AudioClipsCacheManager.AllDone)
{
Plugin.Log.LogError("Failed to load audio clips, no in-flight requests running");
DedupLog.LogWarning("Failed to load audio clips, no in-flight requests running");
}
else
{
Plugin.Log.LogDebug($"Waiting for audio clips to load");
DedupLog.LogWarning("Waiting for audio clips to load");
}
#endif
return;
}
#if DEBUG
DedupLog.Clear();
#endif
var vanillaCompatMode = behaviour.VanillaCompatMode;
// If greater than zero, delay the intro to start playing later.
// If less than zero, start playing before the beginCrankingTimer runs out.