refactor: framework modules log through diary components
- Each module logs through diary.For(<package>): cabana, lagoon, attach, cooler, postcard, beachcomber, lighthouse, centrifugo, flare, phrasebook, wristband, bouncer - App-published *slog.Logger overrides stay first; messages and attributes unchanged - sunscreen: InstallDefault documented as the compatibility entry point; diary wraps every channel - READMEs list diary as a dependency; logging docs: plugins use diary.For
This commit is contained in:
@@ -138,7 +138,7 @@ if err := app.Publish[flare.SubscriptionSource](blogSubscriptions{db: gdb}); err
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `backpack`, `bonfire` and `compass` from this repository.
|
||||
- `backpack`, `bonfire`, `compass` and `diary` (component logger `flare` when the app publishes no logger) from this repository.
|
||||
- `github.com/golang-jwt/jwt/v5` (the ES256 VAPID token).
|
||||
- Everything else is the standard library: `crypto/ecdh`, `crypto/ecdsa`, `crypto/hkdf`, `crypto/aes`, `crypto/cipher` and `net/http`. No Web Push library is used.
|
||||
|
||||
|
||||
@@ -21,8 +21,13 @@ import (
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/compass"
|
||||
"git.golem15.com/golem15/summercms/modules/diary"
|
||||
)
|
||||
|
||||
// moduleLog is flare's logger: records carry component=flare and follow
|
||||
// log.components.flare (diary).
|
||||
var moduleLog = diary.For("flare")
|
||||
|
||||
// DefaultTTL is how long a push service keeps an undelivered message when
|
||||
// push.ttl is not set: four weeks.
|
||||
const DefaultTTL = 2419200 * time.Second
|
||||
@@ -267,10 +272,11 @@ func (s *Service) SetHTTPClient(hc *http.Client) {
|
||||
s.pusher = NewVAPIDPusher(s.cfg, hc)
|
||||
}
|
||||
|
||||
// Logger returns the app logger.
|
||||
// Logger returns the app logger: the logger the application published, else
|
||||
// the flare component logger.
|
||||
func (s *Service) Logger() *slog.Logger {
|
||||
if s == nil || s.log == nil {
|
||||
return slog.Default()
|
||||
return moduleLog
|
||||
}
|
||||
return s.log
|
||||
}
|
||||
@@ -419,5 +425,5 @@ func loggerFromApp(app *backpack.App) *slog.Logger {
|
||||
return log
|
||||
}
|
||||
}
|
||||
return slog.Default()
|
||||
return moduleLog
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user