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:
Jakub Zych
2026-10-21 11:58:22 +02:00
parent 71b99317ad
commit 44291adcca
53 changed files with 185 additions and 130 deletions

View File

@@ -119,7 +119,7 @@ When the compass environment is `production`, missing-key warnings are not logge
## Dependencies
- SummerCMS modules: [backpack](../backpack/README.md), [pact](../pact/README.md), [towel](../towel/README.md).
- SummerCMS modules: [backpack](../backpack/README.md), [diary](../diary/README.md) (component logger `phrasebook` for missing translation keys), [pact](../pact/README.md), [towel](../towel/README.md).
- Third-party: `github.com/goccy/go-yaml`, `github.com/nicksnyder/go-i18n/v2` (CLDR plural rules), `golang.org/x/text/language`.
- Standard library: `context`, `embed`, `fmt`, `io/fs`, `log/slog`, `path`, `regexp`, `sort`, `strconv`, `strings`, `sync`, `unicode`, `unicode/utf8`.

View File

@@ -3,7 +3,6 @@ package phrasebook
import (
"context"
"fmt"
"log/slog"
"slices"
"strconv"
"strings"
@@ -12,6 +11,7 @@ import (
"unicode/utf8"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/diary"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/towel"
"github.com/nicksnyder/go-i18n/v2/i18n"
@@ -19,6 +19,10 @@ import (
"golang.org/x/text/language"
)
// moduleLog is phrasebook's logger: records carry component=phrasebook and follow
// log.components.phrasebook (diary).
var moduleLog = diary.For("phrasebook")
const (
defaultLocale = "en"
defaultFallback = "en"
@@ -213,7 +217,7 @@ func (t *Translator) logMissing(key string) {
if _, loaded := t.missing.LoadOrStore(key, struct{}{}); loaded {
return
}
slog.Warn("phrasebook: missing translation key", "key", key)
moduleLog.Warn("phrasebook: missing translation key", "key", key)
}
func fallbackChain(requested, fallback string) []string {