Agents can read recent S3 log lines without scraping UMM files. TrySetActive changes session state only, so benchmarks and MCP can toggle modules without writing the UMM enabled flags.
64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using System;
|
|
using UnityModManagerNet;
|
|
|
|
namespace S3.Core;
|
|
|
|
/// <summary>
|
|
/// Thin static wrapper over the UMM mod logger so every module can log without
|
|
/// holding a ModEntry reference. Initialized once from <see cref="Main.Load"/>.
|
|
/// </summary>
|
|
public static class Log
|
|
{
|
|
private const int RingN = 200;
|
|
private static readonly object RingLock = new();
|
|
private static readonly string[] Ring = new string[RingN];
|
|
private static int _ringCount;
|
|
|
|
private static UnityModManager.ModEntry.ModLogger? _logger;
|
|
|
|
public static void Init(UnityModManager.ModEntry modEntry) => _logger = modEntry.Logger;
|
|
|
|
public static void Info(string msg)
|
|
{
|
|
Push("INF", msg);
|
|
_logger?.Log(msg);
|
|
}
|
|
|
|
public static void Warn(string msg)
|
|
{
|
|
Push("WRN", msg);
|
|
_logger?.Warning(msg);
|
|
}
|
|
|
|
public static void Error(string msg)
|
|
{
|
|
Push("ERR", msg);
|
|
_logger?.Error(msg);
|
|
}
|
|
|
|
public static string[] Tail(int count)
|
|
{
|
|
if (count < 1) count = 1;
|
|
if (count > RingN) count = RingN;
|
|
lock (RingLock)
|
|
{
|
|
int have = Math.Min(_ringCount, RingN);
|
|
int take = Math.Min(count, have);
|
|
var result = new string[take];
|
|
int start = _ringCount - take;
|
|
for (int i = 0; i < take; i++)
|
|
result[i] = Ring[(start + i) % RingN];
|
|
return result;
|
|
}
|
|
}
|
|
|
|
static void Push(string level, string msg)
|
|
{
|
|
string line = DateTime.Now.ToString("HH:mm:ss") + " [" + level + "] " + msg;
|
|
lock (RingLock)
|
|
{
|
|
Ring[_ringCount % RingN] = line;
|
|
_ringCount++;
|
|
}
|
|
}
|
|
}
|