feat(worker): route Serilog Warn/Error to footer + buffer recent logs for overlay

This commit is contained in:
Mika Kuns
2026-06-26 16:11:49 +02:00
parent eb0ddb56d3
commit 08a4f97a78
7 changed files with 334 additions and 2 deletions
+15 -1
View File
@@ -7,6 +7,7 @@ using ClaudeDo.Worker.Config;
using ClaudeDo.Worker.External;
using ClaudeDo.Worker.Hub;
using ClaudeDo.Worker.Lifecycle;
using ClaudeDo.Worker.Logging;
using ClaudeDo.Worker.Planning;
using ClaudeDo.Worker.Queue;
using ClaudeDo.Worker.Runner;
@@ -34,13 +35,22 @@ var builder = WebApplication.CreateBuilder(args);
var logRoot = cfg.LogRoot;
Directory.CreateDirectory(logRoot);
// In-memory ring + broadcast sink power the footer log strip and the Log Visualizer
// overlay. Created pre-build so Serilog can write to the sink; the SignalR broadcaster
// is attached once the host is built (see below).
var logBuffer = new LogRingBuffer(TimeSpan.FromMinutes(30));
var broadcastSink = new BroadcastLogSink(logBuffer);
builder.Host.UseSerilog((ctx, lc) => lc
.MinimumLevel.Information()
.WriteTo.File(
System.IO.Path.Combine(logRoot, "worker-.log"),
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 7,
shared: true));
shared: true)
.WriteTo.Sink(broadcastSink));
builder.Services.AddSingleton(logBuffer);
builder.Services.AddDbContextFactory<ClaudeDoDbContext>(opt =>
opt.UseSqlite($"Data Source={cfg.DbPath}"));
@@ -180,6 +190,10 @@ builder.WebHost.UseUrls($"http://127.0.0.1:{cfg.SignalRPort}");
var app = builder.Build();
// Now that the hub context exists, let the broadcast sink push Warn/Error to the footer.
var logBroadcaster = app.Services.GetRequiredService<HubBroadcaster>();
broadcastSink.Attach((message, level, ts) => logBroadcaster.WorkerLog(message, level, ts));
using (var scope = app.Services.CreateScope())
{
ClaudeDoDbContext.MigrateAndConfigure(