1
0
Fork 0

Port logging to BepInEx ManualLogSource

- pros: free namespace by default
- cons: Debug level has to be enabled manually in BepInEx.cfg,
  specifically in the section named [Logging.Console]
This commit is contained in:
ivan tkachenko 2025-12-19 23:39:28 +02:00
parent 8a24448cb6
commit 38c9472cb1
4 changed files with 28 additions and 25 deletions

View File

@ -82,7 +82,7 @@ namespace MuzikaGromche
CachedDiscoBalls.Add(discoBall);
discoBall.SetActive(false);
Debug.Log($"{nameof(MuzikaGromche)} {nameof(DiscoBallManager)} Patched tile '{tile.gameObject.name}'");
Plugin.Log.LogDebug($"{nameof(DiscoBallManager)} Patched tile '{tile.gameObject.name}'");
}
static IEnumerable<Animator> FindDiscoBallAnimators(GameObject discoBall)
@ -109,7 +109,7 @@ namespace MuzikaGromche
public static void Toggle(bool on)
{
Debug.Log($"{nameof(MuzikaGromche)} {nameof(DiscoBallManager)} Toggle {(on ? "ON" : "OFF")} {CachedDiscoBallAnimators.Count} animators");
Plugin.Log.LogDebug($"{nameof(DiscoBallManager)} Toggle {(on ? "ON" : "OFF")} {CachedDiscoBallAnimators.Count} animators");
foreach (var discoBall in CachedDiscoBalls)
{
@ -133,7 +133,7 @@ namespace MuzikaGromche
internal static void Clear()
{
Debug.Log($"{nameof(MuzikaGromche)} {nameof(DiscoBallManager)} Clearing {CachedDiscoBalls.Count} disco balls & {CachedDiscoBallAnimators.Count} animators");
Plugin.Log.LogDebug($"{nameof(DiscoBallManager)} Clearing {CachedDiscoBalls.Count} disco balls & {CachedDiscoBallAnimators.Count} animators");
CachedDiscoBallAnimators.Clear();
CachedDiscoBalls.Clear();
}

View File

@ -1,5 +1,6 @@
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
@ -26,6 +27,7 @@ namespace MuzikaGromche
[BepInDependency("BMX.LobbyCompatibility", BepInDependency.DependencyFlags.SoftDependency)]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log = null!;
internal new static Config Config { get; private set; } = null!;
// Not all lights are white by default. For example, Mineshaft's neon light is green-ish.
@ -857,7 +859,7 @@ namespace MuzikaGromche
var rwi = new RandomWeightedIndex(weights);
var trackId = rwi.GetRandomWeightedIndex(seed);
var track = tracks[trackId];
Debug.Log($"{nameof(MuzikaGromche)} Seed is {seed}, chosen track is \"{track.Name}\", #{trackId} of {rwi}");
Log.LogInfo($"Seed is {seed}, chosen track is \"{track.Name}\", #{trackId} of {rwi}");
return tracks[trackId];
}
@ -890,6 +892,8 @@ namespace MuzikaGromche
void Awake()
{
Log = Logger;
// Sort in place by name
Array.Sort(Tracks.Select(track => track.Name).ToArray(), Tracks);
@ -1311,7 +1315,7 @@ namespace MuzikaGromche
void ISelectableTrack.Debug()
{
Debug.Log($"{nameof(MuzikaGromche)} Track \"{Name}\", Intro={LoadedIntro.length:N4}, Loop={LoadedLoop.length:N4}");
Plugin.Log.LogDebug($"Track \"{Name}\", Intro={LoadedIntro.length:N4}, Loop={LoadedLoop.length:N4}");
}
}
@ -1337,10 +1341,10 @@ namespace MuzikaGromche
void ISelectableTrack.Debug()
{
Debug.Log($"{nameof(MuzikaGromche)} Track Group \"{Name}\", Count={Tracks.Length}");
Plugin.Log.LogDebug($"Track Group \"{Name}\", Count={Tracks.Length}");
foreach (var (track, index) in Tracks.Select((x, i) => (x, i)))
{
Debug.Log($"{nameof(MuzikaGromche)} Track {index} \"{track.Name}\", Intro={track.LoadedIntro.length:N4}, Loop={track.LoadedLoop.length:N4}");
Plugin.Log.LogDebug($" Track {index} \"{track.Name}\", Intro={track.LoadedIntro.length:N4}, Loop={track.LoadedLoop.length:N4}");
}
}
}
@ -1717,11 +1721,10 @@ namespace MuzikaGromche
IsLooping |= timestamp.IsLooping;
#if DEBUG && false
Debug.LogFormat("{0} t={1,10:N4} d={2,7:N4} {3} Time={4:N4} norm={5,6:N4} beat={6,7:N4}",
nameof(MuzikaGromche),
Plugin.Log.LogDebug(string.Format("t={0,10:N4} d={1,7:N4} {2} Time={3:N4} norm={4,6:N4} beat={5,7:N4}",
Time.realtimeSinceStartup, Time.deltaTime,
isExtrapolated ? 'E' : '_', time,
adjustedTimeNormalized, beat);
adjustedTimeNormalized, beat));
#endif
return timestamp;
@ -1783,7 +1786,7 @@ namespace MuzikaGromche
LastKnownLoopOffsetBeat = loopOffsetTimestamp.Beat;
var events = GetEvents(loopOffsetTimestamp, loopOffsetSpan, windUpOffsetTimestamp);
#if DEBUG
Debug.Log($"{nameof(MuzikaGromche)} looping? {(LoopLoopingState.IsLooping ? 'X' : '_')}{(WindUpLoopingState.IsLooping ? 'X' : '_')} Loop={loopOffsetSpan} WindUp={windUpOffsetTimestamp} Time={Time.realtimeSinceStartup:N4} events={string.Join(",", events)}");
Plugin.Log.LogDebug($"looping? {(LoopLoopingState.IsLooping ? 'X' : '_')}{(WindUpLoopingState.IsLooping ? 'X' : '_')} Loop={loopOffsetSpan} WindUp={windUpOffsetTimestamp} Time={Time.realtimeSinceStartup:N4} events={string.Join(",", events)}");
#endif
return events;
}
@ -2611,7 +2614,7 @@ namespace MuzikaGromche
}
catch (Exception e)
{
Debug.Log($"{nameof(MuzikaGromche)} Unable to parse time series: {e}");
Plugin.Log.LogError($"Unable to parse time series: {e}");
return null;
}
}
@ -2628,7 +2631,7 @@ namespace MuzikaGromche
strings.Append(", ");
}
}
Debug.Log($"{nameof(MuzikaGromche)} format time series {ts} {strings}");
Plugin.Log.LogDebug($"format time series {ts} {strings}");
return strings.ToString();
}
T[]? parseStringArray<T>(string str, Func<string, T> parser, bool sort = false) where T : struct
@ -2641,7 +2644,7 @@ namespace MuzikaGromche
}
catch (Exception e)
{
Debug.Log($"{nameof(MuzikaGromche)} Unable to parse array: {e}");
Plugin.Log.LogError($"Unable to parse array: {e}");
return null;
}
}
@ -2731,12 +2734,12 @@ namespace MuzikaGromche
.FirstOrDefault(prefab => prefab.Prefab.name == JesterEnemyPrefabName);
if (networkPrefab == null)
{
Debug.LogError($"{nameof(MuzikaGromche)} JesterEnemy prefab not found!");
Plugin.Log.LogError("JesterEnemy prefab not found!");
}
else
{
networkPrefab.Prefab.AddComponent<MuzikaGromcheJesterNetworkBehaviour>();
Debug.Log($"{nameof(MuzikaGromche)} Patched JesterEnemy");
Plugin.Log.LogInfo("Patched JesterEnemy");
}
}
}
@ -2761,7 +2764,7 @@ namespace MuzikaGromche
var farAudioTransform = gameObject.transform.Find("FarAudio");
if (farAudioTransform == null)
{
Debug.LogError($"{nameof(MuzikaGromche)} JesterEnemy->FarAudio prefab not found!");
Plugin.Log.LogError("JesterEnemy->FarAudio prefab not found!");
}
else
{
@ -2788,7 +2791,7 @@ namespace MuzikaGromche
Config.Volume.SettingChanged += UpdateVolume;
Debug.Log($"{nameof(MuzikaGromche)} {nameof(MuzikaGromcheJesterNetworkBehaviour)} Patched JesterEnemy");
Plugin.Log.LogInfo($"{nameof(MuzikaGromcheJesterNetworkBehaviour)} Patched JesterEnemy");
}
}
@ -2856,7 +2859,7 @@ namespace MuzikaGromche
[ClientRpc]
public void SetTrackClientRpc(string name)
{
Debug.Log($"{nameof(MuzikaGromche)} SetTrackClientRpc {name}");
Plugin.Log.LogInfo($"SetTrackClientRpc {name}");
if (Plugin.FindTrackNamed(name) is { } track)
{
CurrentTrack = Config.OverrideCurrentTrack(track);
@ -2868,7 +2871,7 @@ namespace MuzikaGromche
{
var selectableTrack = Plugin.ChooseTrack();
var audioTrack = selectableTrack.SelectTrack(SelectedTrackIndex);
Debug.Log($"{nameof(MuzikaGromche)} ChooseTrackServerRpc {selectableTrack.Name} #{SelectedTrackIndex} {audioTrack.Name}");
Plugin.Log.LogInfo($"ChooseTrackServerRpc {selectableTrack.Name} #{SelectedTrackIndex} {audioTrack.Name}");
SetTrackClientRpc(audioTrack.Name);
SelectedTrackIndex += 1;
}
@ -2877,7 +2880,7 @@ namespace MuzikaGromche
{
double loopStartDspTime = AudioSettings.dspTime + IntroAudioSource.clip.length - IntroAudioSource.time;
LoopAudioSource.PlayScheduled(loopStartDspTime);
Debug.Log($"{nameof(MuzikaGromche)} Play Intro: dspTime={AudioSettings.dspTime:N4}, intro.time={IntroAudioSource.time:N4}/{IntroAudioSource.clip.length:N4}, scheduled Loop={loopStartDspTime}");
Plugin.Log.LogDebug($"Play Intro: dspTime={AudioSettings.dspTime:N4}, intro.time={IntroAudioSource.time:N4}/{IntroAudioSource.clip.length:N4}, scheduled Loop={loopStartDspTime}");
}
public void OverrideDeathScreenGameOverText()
@ -2938,7 +2941,7 @@ namespace MuzikaGromche
if (behaviour.CurrentTrack == null)
{
#if DEBUG
Debug.LogError($"{nameof(MuzikaGromche)} CurrentTrack is not set!");
Plugin.Log.LogError("CurrentTrack is not set!");
#endif
return;
}

View File

@ -205,7 +205,7 @@ namespace MuzikaGromche
patch.ManualPatch?.Invoke(animationContainer);
animator.runtimeAnimatorController = patch.AnimatorController;
Debug.Log($"{nameof(MuzikaGromche)} {nameof(PoweredLightsAnimatorsPatch)} {tilePatch.TileName}/{patch.AnimatorContainerPath}: Replaced animator controller");
Plugin.Log.LogDebug($"{nameof(PoweredLightsAnimatorsPatch)} {tilePatch.TileName}/{patch.AnimatorContainerPath}: Replaced animator controller");
}
}
}
@ -223,7 +223,7 @@ namespace MuzikaGromche
#pragma warning restore CS0162 // Unreachable code detected
}
targetObject.name = newName;
Debug.Log($"{nameof(MuzikaGromche)} {nameof(PoweredLightsAnimatorsPatch)} {animatorContainer.name}/{relativePath}: Renamed GameObject");
Plugin.Log.LogDebug($"{nameof(PoweredLightsAnimatorsPatch)} {animatorContainer.name}/{relativePath}: Renamed GameObject");
};
}

View File

@ -80,7 +80,7 @@ namespace MuzikaGromche
var multiplier = Mathf.Lerp(minMultiplier, maxMultiplier, normalizedMultiplierTime);
var newWeight = Mathf.FloorToInt(weights[index] * multiplier);
Debug.Log($"{nameof(MuzikaGromche)} {nameof(SpawnRatePatch)} Overriding spawn weight[{index}] {weights[index]} * {multiplier} => {newWeight} for t={SpawnTime}");
Plugin.Log.LogInfo($"{nameof(SpawnRatePatch)} Overriding spawn weight[{index}] {weights[index]} * {multiplier} => {newWeight} for t={SpawnTime}");
weights[index] = newWeight;
}
}