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:
@@ -24,7 +24,7 @@ The `centrifugo` sub-package is the Centrifugo driver. It has a hand-rolled `net
|
||||
|
||||
## Role in the framework
|
||||
|
||||
A service module high in the stack: it depends on `backpack`, `bouncer`, `compass`, `conga`, `lagoon`, `pact` and `wire`, and only the summer CLI imports it. The publisher interface is transport-neutral, with the Centrifugo driver in the centrifugo subpackage. It is separate from `festival` (in-process) and `flare` (Web Push) because it needs the database and jobs to send broadcasts only for committed writes.
|
||||
A service module high in the stack: it depends on `backpack`, `bouncer`, `compass`, `conga`, `diary`, `lagoon`, `pact` and `wire`, and only the summer CLI imports it. The publisher interface is transport-neutral, with the Centrifugo driver in the centrifugo subpackage. It is separate from `festival` (in-process) and `flare` (Web Push) because it needs the database and jobs to send broadcasts only for committed writes.
|
||||
|
||||
Use cases:
|
||||
|
||||
@@ -241,7 +241,7 @@ for _, pub := range mem.Publications() {
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `backpack`, `bouncer`, `compass`, `conga` (the broadcast job), `lagoon` (callback installation), `pact` and `wire` from this repository; the centrifugo driver also uses `surf` for the client IP and `bonfire` for its command.
|
||||
- `backpack`, `bouncer`, `compass`, `conga` (the broadcast job), `diary` (component loggers `lighthouse` and `centrifugo`), `lagoon` (callback installation), `pact` and `wire` from this repository; the centrifugo driver also uses `surf` for the client IP and `bonfire` for its command.
|
||||
- `gorm.io/gorm` (broadcast callbacks).
|
||||
- `github.com/golang-jwt/jwt/v5` (centrifugo token signing).
|
||||
- The Centrifugo client is plain `net/http`; no Centrifugo SDK is used.
|
||||
|
||||
@@ -12,9 +12,14 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/diary"
|
||||
"git.golem15.com/golem15/summercms/modules/wire"
|
||||
)
|
||||
|
||||
// moduleLog is centrifugo's logger: records carry component=centrifugo and follow
|
||||
// log.components.centrifugo (diary).
|
||||
var moduleLog = diary.For("centrifugo")
|
||||
|
||||
// requestTimeout bounds every Centrifugo API call, as the WinterCMS client
|
||||
// does.
|
||||
const requestTimeout = 5 * time.Second
|
||||
@@ -54,7 +59,7 @@ func NewClient(cfg Config, hc *http.Client) *Client {
|
||||
apiURL: cfg.APIURL,
|
||||
apiKey: cfg.APIKey,
|
||||
hc: hc,
|
||||
log: slog.Default(),
|
||||
log: moduleLog,
|
||||
now: time.Now,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,15 @@ import (
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/compass"
|
||||
"git.golem15.com/golem15/summercms/modules/diary"
|
||||
"git.golem15.com/golem15/summercms/modules/lagoon"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// moduleLog is lighthouse's logger: records carry component=lighthouse and follow
|
||||
// log.components.lighthouse (diary).
|
||||
var moduleLog = diary.For("lighthouse")
|
||||
|
||||
const (
|
||||
// DefaultDriver is the driver used when realtime.driver is empty.
|
||||
DefaultDriver = "null"
|
||||
@@ -141,10 +146,11 @@ func (s *Service) Registry() *Registry {
|
||||
return s.registry
|
||||
}
|
||||
|
||||
// Logger returns the app logger the service and its driver log through.
|
||||
// Logger returns the app logger the service and its driver log through: the
|
||||
// logger the application published, else the lighthouse component logger.
|
||||
func (s *Service) Logger() *slog.Logger {
|
||||
if s == nil || s.log == nil {
|
||||
return slog.Default()
|
||||
return moduleLog
|
||||
}
|
||||
return s.log
|
||||
}
|
||||
@@ -198,5 +204,5 @@ func loggerFromApp(app *backpack.App) *slog.Logger {
|
||||
return log
|
||||
}
|
||||
}
|
||||
return slog.Default()
|
||||
return moduleLog
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user