Route console diagnostics and stage progress through native reporting

This commit is contained in:
2026-11-20 05:59:09 +00:00
parent c7a5ff316d
commit c523def852
23 changed files with 309 additions and 76 deletions

View File

@@ -1,17 +1,10 @@
package logging
import (
"io"
"log/slog"
"os"
)
// NewLogger creates a text slog logger.
func NewLogger(out io.Writer, level slog.Level) *slog.Logger {
if out == nil {
out = os.Stderr
}
handler := slog.NewTextHandler(out, &slog.HandlerOptions{Level: level})
return slog.New(handler)
// Reporter receives operation diagnostics and work progress. Implementations own
// delivery and visibility; reporting does not change domain execution policy.
type Reporter interface {
Info(message string, fields ...any)
Warn(message string, fields ...any)
Debug(message string, fields ...any)
Progress(message string, fields ...any)
}

View File

@@ -1,31 +0,0 @@
package logging
import (
"bytes"
"log/slog"
"strings"
"testing"
)
func TestNewLoggerWritesOutput(t *testing.T) {
var buf bytes.Buffer
logger := NewLogger(&buf, slog.LevelInfo)
if logger == nil {
t.Fatal("logger is nil")
}
logger.Info("hello", "component", "test")
out := buf.String()
if !strings.Contains(out, "hello") {
t.Fatalf("output = %q, want to contain message", out)
}
}
func TestNewLoggerNilWriter(t *testing.T) {
logger := NewLogger(nil, slog.LevelInfo)
if logger == nil {
t.Fatal("logger is nil")
}
logger.Info("should not panic")
}