forked from nikita/muzika-gromche
Deduplicate logs to avoid spamming console with errors each frame
This commit is contained in:
parent
a254188f0c
commit
a2cf66476c
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
@ -3332,20 +3338,22 @@ 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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue