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

@@ -12,7 +12,7 @@ bouncer decides who is making a request. Guards (`bouncer.Guard`, `bouncer.Crede
## Role in the framework
A dependency-free security primitive. `surf` uses it for request guards, `cabana` for admin sign-in, and `conga` and `lighthouse` for authenticated workers and realtime tokens. It is separate so authentication code can be reviewed and tested on its own, without the HTTP or admin layers around it.
A security primitive whose only framework dependency is `diary`, for the turnstile log lines. `surf` uses it for request guards, `cabana` for admin sign-in, and `conga` and `lighthouse` for authenticated workers and realtime tokens. It is separate so authentication code can be reviewed and tested on its own, without the HTTP or admin layers around it.
Use cases:
@@ -198,7 +198,7 @@ Environment variables follow the compass mapping, for example `SUMMER_AUTH__COOK
## Dependencies
- SummerCMS modules: none.
- SummerCMS modules: [diary](../diary/README.md) (component logger `bouncer` for the turnstile verification lines).
- Third-party: `github.com/golang-jwt/jwt/v5`, `golang.org/x/crypto/bcrypt`.
- Standard library: `bytes`, `context`, `crypto/rand`, `database/sql`, `encoding/hex`, `encoding/json`, `errors`, `fmt`, `io`, `log/slog`, `math`, `mime`, `net`, `net/http`, `net/url`, `reflect`, `regexp`, `strconv`, `strings`, `sync`, `time`.
- Tests additionally use `github.com/testcontainers/testcontainers-go` with its `modules/postgres` package, and `github.com/jackc/pgx/v5/stdlib`.

View File

@@ -7,15 +7,20 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"mime"
"net"
"net/http"
"net/url"
"strings"
"time"
"git.golem15.com/golem15/summercms/modules/diary"
)
// moduleLog is bouncer's logger: records carry component=bouncer and follow
// log.components.bouncer (diary).
var moduleLog = diary.For("bouncer")
const (
// TurnstileSiteverifyURL is Cloudflare's server-side validation endpoint.
TurnstileSiteverifyURL = "https://challenges.cloudflare.com/turnstile/v0/siteverify"
@@ -230,9 +235,9 @@ func (t *Turnstile) Middleware(failClosed bool, field string, clientIP func(*htt
verdict, verr := t.Verify(r.Context(), token, clientIP(r), failClosed)
if verr != nil {
if errors.Is(verr, errTurnstileRefused) {
slog.DebugContext(r.Context(), "bouncer: turnstile token refused", "error", verr.Error())
moduleLog.DebugContext(r.Context(), "bouncer: turnstile token refused", "error", verr.Error())
} else {
slog.WarnContext(r.Context(), "bouncer: turnstile verification failed", "error", verr.Error())
moduleLog.WarnContext(r.Context(), "bouncer: turnstile verification failed", "error", verr.Error())
}
}
switch verdict {