MCPcopy Create free account
hub / github.com/compozy/agh / TestNewWritesStructuredLogsToFile

Function TestNewWritesStructuredLogsToFile

internal/logger/logger_test.go:10–31  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestNewWritesStructuredLogsToFile(t *testing.T) {
11 logFile := filepath.Join(t.TempDir(), "logs", "agh.log")
12
13 log, closeFn, err := New(WithLevel("debug"), WithFile(logFile), WithMirrorToStderr(false))
14 if err != nil {
15 t.Fatalf("New() error = %v", err)
16 }
17
18 log.Info("hello", "component", "test")
19
20 if err := closeFn(); err != nil {
21 t.Fatalf("closeFn() error = %v", err)
22 }
23
24 data, err := os.ReadFile(logFile)
25 if err != nil {
26 t.Fatalf("ReadFile() error = %v", err)
27 }
28 if !strings.Contains(string(data), `"msg":"hello"`) {
29 t.Fatalf("log file = %q, want hello message", string(data))
30 }
31}
32
33func TestNewWithFileRotation(t *testing.T) {
34 t.Parallel()

Callers

nothing calls this directly

Calls 7

WithLevelFunction · 0.85
WithFileFunction · 0.85
WithMirrorToStderrFunction · 0.85
ContainsMethod · 0.80
NewFunction · 0.70
InfoMethod · 0.65
ReadFileMethod · 0.65

Tested by

no test coverage detected