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);
|
Array.Sort(Tracks.Select(track => track.Name).ToArray(), Tracks);
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
JesterPatch.DedupLog = new DedupManualLogSource(Logger);
|
||||||
GlobalBehaviour.Instance.StartCoroutine(PreloadDebugAndExport(Tracks));
|
GlobalBehaviour.Instance.StartCoroutine(PreloadDebugAndExport(Tracks));
|
||||||
#endif
|
#endif
|
||||||
Config = new Config(base.Config);
|
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))]
|
[HarmonyPatch(nameof(JesterAI.Update))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
static void JesterUpdatePostfix(JesterAI __instance, State __state)
|
static void JesterUpdatePostfix(JesterAI __instance, State __state)
|
||||||
|
|
@ -3331,21 +3337,23 @@ namespace MuzikaGromche
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (behaviour.CurrentTrack == null)
|
if (behaviour.CurrentTrack == null)
|
||||||
{
|
{
|
||||||
Plugin.Log.LogError("CurrentTrack is not set!");
|
DedupLog.LogWarning("CurrentTrack is not set!");
|
||||||
}
|
}
|
||||||
else if (AudioClipsCacheManager.AllDone)
|
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
|
else
|
||||||
{
|
{
|
||||||
Plugin.Log.LogDebug($"Waiting for audio clips to load");
|
DedupLog.LogWarning("Waiting for audio clips to load");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#if DEBUG
|
||||||
|
DedupLog.Clear();
|
||||||
|
#endif
|
||||||
var vanillaCompatMode = behaviour.VanillaCompatMode;
|
var vanillaCompatMode = behaviour.VanillaCompatMode;
|
||||||
// If greater than zero, delay the intro to start playing later.
|
// If greater than zero, delay the intro to start playing later.
|
||||||
// If less than zero, start playing before the beginCrankingTimer runs out.
|
// If less than zero, start playing before the beginCrankingTimer runs out.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue