feat(conga,lagoon): River and GORM log through diary components
- River's logger is diary.For("river") (warn by default), conga's own lines diary.For("conga"); an app-published logger still wins
- GORM logs through logger.NewSlogLogger(diary.For("db")): warn level, record-not-found ignored, parameterized SQL traces only at verbosity 3
- Smoke tests TestRiverLoggerUsesDiarySmoke and TestGormLoggerUsesDiarySmoke
This commit is contained in:
45
modules/conga/logger_smoke_test.go
Normal file
45
modules/conga/logger_smoke_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package conga
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/bonfire"
|
||||
"git.golem15.com/golem15/summercms/modules/compass"
|
||||
"git.golem15.com/golem15/summercms/modules/diary"
|
||||
)
|
||||
|
||||
// TestRiverLoggerUsesDiarySmoke: River logs through the diary component
|
||||
// river unless the application publishes its own logger, and conga's own
|
||||
// lines use component conga.
|
||||
func TestRiverLoggerUsesDiarySmoke(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
t.Cleanup(diary.Reset)
|
||||
diary.Bootstrap(&buf, diary.Options{Color: bonfire.ColorNever})
|
||||
|
||||
riverLogger(nil).Warn("probe")
|
||||
if !strings.Contains(buf.String(), "component=river") {
|
||||
t.Fatalf("River record lacks component=river:\n%s", buf.String())
|
||||
}
|
||||
loggerFromApp(nil).Warn("own line")
|
||||
if !strings.Contains(buf.String(), "component=conga") {
|
||||
t.Fatalf("conga record lacks component=conga:\n%s", buf.String())
|
||||
}
|
||||
|
||||
var capture bytes.Buffer
|
||||
app := backpack.New(&compass.Config{})
|
||||
if err := app.Publish(slog.New(slog.NewTextHandler(&capture, nil))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buf.Reset()
|
||||
riverLogger(app).Warn("published probe")
|
||||
if !strings.Contains(capture.String(), "published probe") {
|
||||
t.Fatalf("published logger did not receive the River record:\n%s", capture.String())
|
||||
}
|
||||
if strings.Contains(buf.String(), "published probe") {
|
||||
t.Fatalf("River record reached diary although the app published a logger:\n%s", buf.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user