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:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/diary"
|
||||
"github.com/riverqueue/river"
|
||||
"github.com/riverqueue/river/riverdriver/riverdatabasesql"
|
||||
)
|
||||
@@ -113,11 +114,37 @@ func newInsertClient(sqlDB *sql.DB, s settings, log *slog.Logger) (*river.Client
|
||||
return river.NewClient(riverdatabasesql.New(sqlDB), baseConfig(s, log))
|
||||
}
|
||||
|
||||
func loggerFromApp(app *backpack.App) *slog.Logger {
|
||||
// moduleLog is the logger of conga's own lines (component conga).
|
||||
var moduleLog = diary.For("conga")
|
||||
|
||||
// riverLog is River's logger (component river). The framework default
|
||||
// log.components.river: warn keeps River's info lines out of the console.
|
||||
var riverLog = diary.For("river")
|
||||
|
||||
// publishedLogger returns the *slog.Logger the application published, if any.
|
||||
func publishedLogger(app *backpack.App) (*slog.Logger, bool) {
|
||||
if app != nil {
|
||||
if log, ok := app.Lookup[*slog.Logger](); ok && log != nil {
|
||||
return log
|
||||
return log, true
|
||||
}
|
||||
}
|
||||
return slog.Default()
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// loggerFromApp is the logger of conga's own lines: the logger the
|
||||
// application published, else the conga component logger.
|
||||
func loggerFromApp(app *backpack.App) *slog.Logger {
|
||||
if log, ok := publishedLogger(app); ok {
|
||||
return log
|
||||
}
|
||||
return moduleLog
|
||||
}
|
||||
|
||||
// riverLogger is the logger handed to River: the logger the application
|
||||
// published, else diary.For("river").
|
||||
func riverLogger(app *backpack.App) *slog.Logger {
|
||||
if log, ok := publishedLogger(app); ok {
|
||||
return log
|
||||
}
|
||||
return riverLog
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user