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

@@ -370,7 +370,7 @@ TOKEN=$(./bin/acme admin:token:create admin@example.com --name agent --scope blo
## Dependencies
- SummerCMS modules: [backpack](../backpack/README.md), [boardwalk](../boardwalk/README.md), [bonfire](../bonfire/README.md), [bouncer](../bouncer/README.md), [lagoon](../lagoon/README.md), [pact](../pact/README.md), [party](../party/README.md), [phrasebook](../phrasebook/README.md), [seaglass](../seaglass/README.md) (sanitizes `richeditor` values), [towel](../towel/README.md).
- SummerCMS modules: [backpack](../backpack/README.md), [boardwalk](../boardwalk/README.md), [bonfire](../bonfire/README.md), [bouncer](../bouncer/README.md), [diary](../diary/README.md) (component logger `cabana`; the `admin.auth` audit record keeps its message), [lagoon](../lagoon/README.md), [pact](../pact/README.md), [party](../party/README.md), [phrasebook](../phrasebook/README.md), [seaglass](../seaglass/README.md) (sanitizes `richeditor` values), [towel](../towel/README.md).
- Third-party: `gorm.io/gorm` (with `gorm.io/gorm/clause`), `github.com/goccy/go-yaml` (with its `ast` package), `golang.org/x/net/html` (with its `atom` package; parses rendered partials for the allowlist walk).
- Standard library: `bytes`, `context`, `crypto/sha256`, `database/sql`, `encoding/hex`, `encoding/json`, `errors`, `fmt`, `html/template`, `io`, `io/fs`, `log/slog`, `math`, `net`, `net/http`, `path`, `reflect`, `regexp`, `sort`, `strconv`, `strings`, `time`, `unicode/utf8`.
- Tests additionally use `github.com/testcontainers/testcontainers-go` and its `modules/postgres` package, and [signpost](../signpost/README.md) for the dependent dropdown fixture.

View File

@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"io"
"log/slog"
"net/http"
"slices"
"strconv"
@@ -170,7 +169,7 @@ func (s *service) profileFor(ctx context.Context, db *gorm.DB, user BackendUser)
func (s *service) avatarOf(ctx context.Context, db *gorm.DB, userID uint) *AdminAvatar {
f, err := BackendUserAvatar(ctx, db, userID)
if err != nil {
slog.Default().WarnContext(ctx, "cabana: avatar lookup failed", "admin_id", userID, "error", err)
moduleLog.WarnContext(ctx, "cabana: avatar lookup failed", "admin_id", userID, "error", err)
return nil
}
if f == nil || !f.Public() {
@@ -180,7 +179,7 @@ func (s *service) avatarOf(ctx context.Context, db *gorm.DB, userID uint) *Admin
if bucket := s.bucket(); bucket != nil && slices.Contains(attach.AllowedImageMIMEs, f.ContentType) {
thumb, err := f.Thumb(ctx, bucket, avatarThumbEdge, avatarThumbEdge, "crop")
if err != nil {
slog.Default().WarnContext(ctx, "cabana: avatar thumbnail failed", "admin_id", userID, "file_id", f.ID, "error", err)
moduleLog.WarnContext(ctx, "cabana: avatar thumbnail failed", "admin_id", userID, "file_id", f.ID, "error", err)
} else {
out.ThumbURL = thumb
}
@@ -304,7 +303,7 @@ func (s *service) accountUpdate(w http.ResponseWriter, r *http.Request) {
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account update without a database", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account update without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -411,7 +410,7 @@ func (s *service) accountUpdate(w http.ResponseWriter, r *http.Request) {
if _, fromCookie := sessionToken(r); fromCookie {
token, _, err := bouncer.MintAudience(s.secret, uitoa(principal.ID), s.issuer, s.ttl, bouncer.AudienceBackend)
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: minting the session after a password change failed", "admin_id", principal.ID, "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: minting the session after a password change failed", "admin_id", principal.ID, "error", err)
} else {
s.writeSessionCookie(w, token)
}
@@ -437,7 +436,7 @@ func (s *service) revokePresentedToken(r *http.Request) {
expiresAt = until
}
if err := s.bl.Add(r.Context(), jti, expiresAt, time.Now()); err != nil {
slog.Default().WarnContext(r.Context(), "cabana: revoking the token after a password change failed", "error", err)
moduleLog.WarnContext(r.Context(), "cabana: revoking the token after a password change failed", "error", err)
}
}
@@ -501,7 +500,7 @@ func (s *service) writeAccountError(w http.ResponseWriter, r *http.Request, err
var ve *ValidationError
var tooBig *http.MaxBytesError
if !errors.As(err, &ve) && !errors.As(err, &tooBig) {
slog.Default().ErrorContext(r.Context(), "cabana: account route failed", "path", r.URL.Path, "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account route failed", "path", r.URL.Path, "error", err)
}
writeCRUDError(w, err)
}
@@ -548,11 +547,11 @@ func deleteAvatarBlobs(ctx context.Context, tx *gorm.DB, bucket *blob.Bucket, us
}
lagoon.AfterCommit(ctx, tx, func(ctx context.Context, _ *gorm.DB) {
if bucket == nil {
slog.Default().WarnContext(ctx, "cabana: no storage bucket; blobs of a removed avatar were kept", "admin_id", userID)
moduleLog.WarnContext(ctx, "cabana: no storage bucket; blobs of a removed avatar were kept", "admin_id", userID)
return
}
if err := attach.DeleteKeys(context.WithoutCancel(ctx), bucket, keys); err != nil {
slog.Default().WarnContext(ctx, "cabana: deleting a removed avatar's blobs failed", "admin_id", userID, "error", err)
moduleLog.WarnContext(ctx, "cabana: deleting a removed avatar's blobs failed", "admin_id", userID, "error", err)
}
})
}
@@ -569,13 +568,13 @@ func (s *service) avatarUpload(w http.ResponseWriter, r *http.Request) {
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: avatar upload without a database", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: avatar upload without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
bucket := s.bucket()
if bucket == nil {
slog.Default().ErrorContext(r.Context(), "cabana: avatar upload without a storage bucket")
moduleLog.ErrorContext(r.Context(), "cabana: avatar upload without a storage bucket")
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -655,7 +654,7 @@ func (s *service) avatarRemove(w http.ResponseWriter, r *http.Request) {
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: avatar removal without a database", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: avatar removal without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}

View File

@@ -3,7 +3,6 @@ package cabana
import (
"context"
"errors"
"log/slog"
"net/http"
"slices"
"sort"
@@ -60,7 +59,7 @@ func (s *service) accountPreferencesGet(w http.ResponseWriter, r *http.Request)
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account preferences without a database", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account preferences without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -104,7 +103,7 @@ func (s *service) accountPreferencesUpdate(w http.ResponseWriter, r *http.Reques
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(ctx, "cabana: account preferences without a database", "error", err)
moduleLog.ErrorContext(ctx, "cabana: account preferences without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}

View File

@@ -2,7 +2,6 @@ package cabana
import (
"context"
"log/slog"
"net/http"
"strconv"
"strings"
@@ -56,7 +55,7 @@ func (s *service) accountTokensList(w http.ResponseWriter, r *http.Request) {
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account tokens list without a database", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account tokens list without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -71,7 +70,7 @@ func (s *service) accountTokensList(w http.ResponseWriter, r *http.Request) {
}
var rows []BackendAPIToken
if err := q.Order("created_at DESC").Order("id DESC").Find(&rows).Error; err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account tokens list", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account tokens list", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -114,14 +113,14 @@ func (s *service) accountTokenCreate(w http.ResponseWriter, r *http.Request) {
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account token create without a database", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account token create without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
now := time.Now().UTC()
plain, row, details, err := issueAPIToken(db, s.reg, principal, name, expires, scopes, now, false)
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account token create", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account token create", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -148,14 +147,14 @@ func (s *service) accountTokenRevoke(w http.ResponseWriter, r *http.Request) {
}
db, err := s.db()
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account token revoke without a database", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account token revoke without a database", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
revokedBy := principal.ID
row, notFound, err := revokeAPIToken(db, principal.ID, uint(id), &revokedBy)
if err != nil {
slog.Default().ErrorContext(r.Context(), "cabana: account token revoke", "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: account token revoke", "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}

View File

@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"io"
"log/slog"
"net/http"
"git.golem15.com/golem15/summercms/modules/bouncer"
@@ -163,7 +162,7 @@ func (s *service) bulkAction(w http.ResponseWriter, r *http.Request) {
if principal, _ := bouncer.User(r.Context()); principal != nil {
adminID = principal.ID
}
slog.Info("cabana: admin bulk action", "controller", controllerID(cc), "action", name, "admin_id", adminID, "affected", result.Affected)
moduleLog.Info("cabana: admin bulk action", "controller", controllerID(cc), "action", name, "admin_id", adminID, "affected", result.Affected)
WriteData(w, http.StatusOK, result, nil)
})
}
@@ -229,7 +228,7 @@ func (s *service) recordAction(w http.ResponseWriter, r *http.Request) {
if principal, _ := bouncer.User(r.Context()); principal != nil {
adminID = principal.ID
}
slog.Info("cabana: admin record action", "controller", controllerID(cc), "action", name, "admin_id", adminID, "record_id", id)
moduleLog.Info("cabana: admin record action", "controller", controllerID(cc), "action", name, "admin_id", adminID, "record_id", id)
WriteData(w, http.StatusOK, result, nil)
})
}
@@ -288,7 +287,7 @@ func (s *service) runAction(w http.ResponseWriter, r *http.Request, cc *Compiled
writeCRUDError(w, localizeControllerError(ctx, tr, err))
return
}
slog.Error("cabana: admin action failed", "controller", controllerID(cc), "action", action.Name, "field", input.Field, "error", err)
moduleLog.Error("cabana: admin action failed", "controller", controllerID(cc), "action", action.Name, "field", input.Field, "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -299,7 +298,7 @@ func (s *service) runAction(w http.ResponseWriter, r *http.Request, cc *Compiled
if result.Data != nil {
raw, err := json.Marshal(result.Data)
if err != nil || len(raw) > maxActionDataBytes {
slog.Error("cabana: admin action data rejected", "controller", controllerID(cc), "action", action.Name, "field", input.Field, "bytes", len(raw), "error", err)
moduleLog.Error("cabana: admin action data rejected", "controller", controllerID(cc), "action", action.Name, "field", input.Field, "bytes", len(raw), "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}

View File

@@ -6,7 +6,6 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"log/slog"
"strings"
"sync"
"time"
@@ -301,6 +300,6 @@ func stampLastUsed(ctx context.Context, stamps *stampThrottle, store tokenStore,
return
}
if err := store.StampLastUsed(ctx, id, now); err != nil {
slog.Default().WarnContext(ctx, "cabana: token last_used_at stamp failed", "token_id", id, "error", err)
moduleLog.WarnContext(ctx, "cabana: token last_used_at stamp failed", "token_id", id, "error", err)
}
}

View File

@@ -5,7 +5,6 @@ import (
"database/sql"
"encoding/json"
"errors"
"log/slog"
"net"
"net/http"
"strconv"
@@ -392,7 +391,7 @@ func (s *service) logAuth(r *http.Request, outcome string, adminID uint) {
if adminID != 0 {
args = append(args, "admin_id", adminID)
}
slog.Default().Info("admin.auth", args...)
moduleLog.Info("admin.auth", args...)
}
func adminBlacklist(app *backpack.App) bouncer.BlacklistStore {

View File

@@ -3,7 +3,6 @@ package cabana
import (
"bytes"
"encoding/json"
"log/slog"
"net/http"
"strings"
"time"
@@ -288,7 +287,7 @@ func WriteErrorDetails(w http.ResponseWriter, status int, code, message string,
func writeJSON(w http.ResponseWriter, status int, body any) {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(body); err != nil {
slog.Error("cabana: response could not be encoded", "status", status, "error", err)
moduleLog.Error("cabana: response could not be encoded", "status", status, "error", err)
buf.Reset()
_ = json.NewEncoder(&buf).Encode(map[string]any{
"error": map[string]any{"code": "error", "message": msgServerError, "details": map[string]any{}},

View File

@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"errors"
"log/slog"
"math"
"net/http"
"reflect"
@@ -485,7 +484,7 @@ func actionFailure(cc *CompiledController, kind, name string, err error) error {
out := lifecycleFailure(cc, err)
var life *lifecycleError
if errors.As(out, &life) && !errors.As(err, &life) {
slog.Error("cabana: admin "+kind+" failed", "controller", controllerID(cc), "action", name, "error", err)
moduleLog.Error("cabana: admin "+kind+" failed", "controller", controllerID(cc), "action", name, "error", err)
}
return out
}

View File

@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"net/http"
"reflect"
"strconv"
@@ -247,7 +246,7 @@ func (s *service) dependentOptionsRoute(w http.ResponseWriter, r *http.Request)
}
set, err := dependentOptions(r.Context(), cc, field.Name, field.DependsOn, value)
if err != nil {
slog.Error("cabana: dependent options failed", "controller", controllerID(cc), "field", field.Name, "error", err)
moduleLog.Error("cabana: dependent options failed", "controller", controllerID(cc), "field", field.Name, "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}

View File

@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"math"
"net/http"
"regexp"
@@ -640,7 +639,7 @@ func fileItem(ctx context.Context, bucket *blob.Bucket, cf *compiledFile, f *att
if bucket != nil && slices.Contains(attach.AllowedImageMIMEs, f.ContentType) {
thumb, err := f.Thumb(ctx, bucket, cf.thumbW, cf.thumbH, cf.thumbMode)
if err != nil {
slog.Default().WarnContext(ctx, "cabana: file thumbnail failed", "file_id", f.ID, "error", err)
moduleLog.WarnContext(ctx, "cabana: file thumbnail failed", "file_id", f.ID, "error", err)
} else {
item.ThumbURL = thumb
}
@@ -707,7 +706,7 @@ func (s *service) fileUploadOn(w http.ResponseWriter, r *http.Request, cc *Compi
}
bucket := s.bucket()
if bucket == nil {
slog.Default().ErrorContext(r.Context(), "cabana: file upload without a storage bucket", "controller", controllerID(cc))
moduleLog.ErrorContext(r.Context(), "cabana: file upload without a storage bucket", "controller", controllerID(cc))
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -854,7 +853,7 @@ func logFileFailure(r *http.Request, err error) {
return
}
controller := r.PathValue("vendor") + "." + r.PathValue("plugin") + "." + r.PathValue("controller")
slog.Default().ErrorContext(r.Context(), "cabana: file route failed", "controller", controller, "field", r.PathValue("field"), "error", err)
moduleLog.ErrorContext(r.Context(), "cabana: file route failed", "controller", controller, "field", r.PathValue("field"), "error", err)
}
// bodyReader remembers the first read error of the request body other than
@@ -1163,11 +1162,11 @@ func deleteBlobsAfterCommit(ctx context.Context, tx *gorm.DB, bucket *blob.Bucke
keys := attach.BlobKeys(f)
lagoon.AfterCommit(ctx, tx, func(ctx context.Context, _ *gorm.DB) {
if bucket == nil {
slog.Default().WarnContext(ctx, "cabana: no storage bucket; blobs of a deleted file were kept", "file_id", f.ID)
moduleLog.WarnContext(ctx, "cabana: no storage bucket; blobs of a deleted file were kept", "file_id", f.ID)
return
}
if err := attach.DeleteKeys(ctx, bucket, keys); err != nil {
slog.Default().WarnContext(ctx, "cabana: deleting a file's blobs failed", "file_id", f.ID, "error", err)
moduleLog.WarnContext(ctx, "cabana: deleting a file's blobs failed", "file_id", f.ID, "error", err)
}
})
}
@@ -1409,7 +1408,7 @@ func (s *service) serveProtectedFileOn(w http.ResponseWriter, r *http.Request, c
}
bucket := s.bucket()
if bucket == nil {
slog.Default().ErrorContext(r.Context(), "cabana: protected file route without a storage bucket", "controller", controllerID(cc))
moduleLog.ErrorContext(r.Context(), "cabana: protected file route without a storage bucket", "controller", controllerID(cc))
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -1438,7 +1437,7 @@ func (s *service) serveProtectedFileOn(w http.ResponseWriter, r *http.Request, c
}
key, err = f.ThumbKey(ctx, bucket, cf.thumbW, cf.thumbH, cf.thumbMode)
if err != nil {
slog.Default().ErrorContext(ctx, "cabana: protected thumbnail failed", "file_id", f.ID, "error", err)
moduleLog.ErrorContext(ctx, "cabana: protected thumbnail failed", "file_id", f.ID, "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -1450,7 +1449,7 @@ func (s *service) serveProtectedFileOn(w http.ResponseWriter, r *http.Request, c
writeNotFound(w, r)
return
}
slog.Default().ErrorContext(ctx, "cabana: protected file read failed", "file_id", f.ID, "error", err)
moduleLog.ErrorContext(ctx, "cabana: protected file read failed", "file_id", f.ID, "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}

View File

@@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"
"reflect"
"regexp"
@@ -686,7 +685,7 @@ func fieldTypeFailure(ctx context.Context, tr *phrasebook.Translator, cc *Compil
// opaqueFieldTypeFailure logs a plugin field type's error and returns the
// opaque lifecycle error (500 without the plugin's text).
func opaqueFieldTypeFailure(cc *CompiledController, field FormField, stage string, err error) error {
slog.Error("cabana: field type "+stage+" failed", "controller", controllerID(cc), "field", field.Name, "type", field.Type, "error", err)
moduleLog.Error("cabana: field type "+stage+" failed", "controller", controllerID(cc), "field", field.Name, "type", field.Type, "error", err)
return &lifecycleError{ControllerID: controllerID(cc)}
}

View File

@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"reflect"
"slices"
@@ -779,7 +778,7 @@ func (s *service) formSchema(w http.ResponseWriter, r *http.Request) {
// A permission editor's options are the controller's answer for this
// administrator (D-16); kept is this request's own slice.
if err := localizePermissionOptions(r.Context(), s.translator(), cc, kept); err != nil {
slog.Error("cabana: permission options failed", "controller", controllerID(cc), "error", err)
moduleLog.Error("cabana: permission options failed", "controller", controllerID(cc), "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
return
}
@@ -1046,7 +1045,7 @@ func (s *service) enabledContentLocales(ctx context.Context) []string {
}
codes, err := writer.EnabledLocales(ctx, db)
if err != nil {
slog.Error("cabana: enabled locales", "error", err)
moduleLog.Error("cabana: enabled locales", "error", err)
return nil
}
// The SPA opens every ML control on the first code, and the default
@@ -1054,7 +1053,7 @@ func (s *service) enabledContentLocales(ctx context.Context) []string {
// and the other codes keep the writer's order.
def, err := writer.DefaultLocale(ctx, db)
if err != nil {
slog.Error("cabana: default locale", "error", err)
moduleLog.Error("cabana: default locale", "error", err)
return codes
}
if i := slices.Index(codes, def); def != "" && i > 0 {

7
modules/cabana/log.go Normal file
View File

@@ -0,0 +1,7 @@
package cabana
import "git.golem15.com/golem15/summercms/modules/diary"
// moduleLog is cabana's logger: records carry component=cabana and follow
// log.components.cabana (diary).
var moduleLog = diary.For("cabana")

View File

@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"html/template"
"log/slog"
"net/http"
"reflect"
"strconv"
@@ -528,7 +527,7 @@ func (s *service) partial(w http.ResponseWriter, r *http.Request) {
tr := s.translator()
ctx := towel.WithLocale(r.Context(), schemaLocale(r.Context(), tr))
fail := func(reason string, err error) {
slog.Error("cabana: admin partial failed", "controller", controllerID(cc), "partial", name, "reason", reason, "error", err)
moduleLog.Error("cabana: admin partial failed", "controller", controllerID(cc), "partial", name, "reason", reason, "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
}
vm, err := provider.PartialData(ctx, name, record)

View File

@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"
"reflect"
"slices"
@@ -154,7 +153,7 @@ func ExecuteList(ctx context.Context, db *gorm.DB, cc *CompiledController, in Li
}
if hook, ok := cc.Controller.(pact.ListExtendRecords); ok && hook != nil && len(records) > 0 {
if err := hook.ListExtendRecords(ctx, db.WithContext(ctx), records); err != nil {
slog.Error("cabana: list extend records failed", "controller", controllerID(cc), "error", err)
moduleLog.Error("cabana: list extend records failed", "controller", controllerID(cc), "error", err)
return nil, err
}
}
@@ -195,11 +194,11 @@ func listRowStates(ctx context.Context, db *gorm.DB, cc *CompiledController, rec
}
result, err := hook.ListRowStates(ctx, db.WithContext(ctx), records)
if err != nil {
slog.Error("cabana: list row states failed", "controller", controllerID(cc), "error", err)
moduleLog.Error("cabana: list row states failed", "controller", controllerID(cc), "error", err)
return nil, err
}
if len(result) != len(records) {
slog.Error("cabana: list row states are not aligned with the page", "controller", controllerID(cc), "records", len(records), "states", len(result))
moduleLog.Error("cabana: list row states are not aligned with the page", "controller", controllerID(cc), "records", len(records), "states", len(result))
return nil, fmt.Errorf("cabana: controller %s returned %d row states for %d records", controllerID(cc), len(result), len(records))
}
var out map[string][]string
@@ -210,7 +209,7 @@ func listRowStates(ctx context.Context, db *gorm.DB, cc *CompiledController, rec
has := map[pact.RowState]bool{}
for _, state := range states {
if !slices.Contains(rowStateOrder, state) {
slog.Warn("cabana: unknown list row state dropped", "controller", controllerID(cc), "state", string(state))
moduleLog.Warn("cabana: unknown list row state dropped", "controller", controllerID(cc), "state", string(state))
continue
}
has[state] = true

View File

@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"math"
"net/http"
"reflect"
@@ -412,7 +411,7 @@ func relationLocks(ctx context.Context, cc *CompiledController, field string) (m
}
lock, err := provider.AdminRelationLocks(ctx, field)
if err != nil {
slog.Error("cabana: relation locks failed", "controller", controllerID(cc), "field", field, "error", err)
moduleLog.Error("cabana: relation locks failed", "controller", controllerID(cc), "field", field, "error", err)
return nil, "", lifecycleFailure(cc, err)
}
if len(lock.IDs) == 0 {

View File

@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io/fs"
"log/slog"
"net/http"
"path"
"reflect"
@@ -381,7 +380,7 @@ func (s *service) writeReorderError(w http.ResponseWriter, r *http.Request, cc *
var ve *ValidationError
var missing recordNotFound
if !errors.As(err, &ve) && !errors.As(err, &missing) {
slog.Error("cabana: reorder failed", "controller", controllerID(cc), "error", err)
moduleLog.Error("cabana: reorder failed", "controller", controllerID(cc), "error", err)
}
writeCRUDError(w, err)
}

View File

@@ -2,7 +2,6 @@ package cabana
import (
"errors"
"log/slog"
"net/http"
"git.golem15.com/golem15/summercms/modules/pact"
@@ -101,7 +100,7 @@ func (s *service) singletonRoute(w http.ResponseWriter, r *http.Request) {
if err != nil {
var missing recordNotFound
if !errors.As(err, &missing) {
slog.Error("cabana: singleton record failed", "controller", controllerID(cc), "error", err)
moduleLog.Error("cabana: singleton record failed", "controller", controllerID(cc), "error", err)
}
// A refusal from SingletonRecord carries plugin phrase keys.
writeCRUDError(w, localizeControllerError(ctx, s.translator(), err))

View File

@@ -3,7 +3,6 @@ package cabana
import (
"crypto/subtle"
"errors"
"log/slog"
"net"
"net/http"
"strings"
@@ -248,5 +247,5 @@ func logTokenAuth(r *http.Request, outcome string, adminID, tokenID uint) {
if tokenID != 0 {
args = append(args, "token_id", tokenID)
}
slog.Default().Info("admin.auth", args...)
moduleLog.Info("admin.auth", args...)
}