feat: console help, examples and named loggers (SummerCMS v0.4.0)
Every command gets long help and examples, descriptions in imperative sentence case, and a warn-only TestCommandsDocumented over bonfire.CheckDocs. The plugin logs through a diary component logger instead of the process default logger. Requires SummerCMS v0.4.0; command names and flags unchanged.
This commit is contained in:
@@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -128,7 +127,7 @@ func authorAvatar(ctx context.Context, db *gorm.DB, userID uint) any {
|
||||
}
|
||||
f, err := cabana.BackendUserAvatar(ctx, db, userID)
|
||||
if err != nil {
|
||||
slog.Default().WarnContext(ctx, "journal api: author avatar lookup failed", "author", userID, "error", err)
|
||||
pluginLog.WarnContext(ctx, "journal api: author avatar lookup failed", "author", userID, "error", err)
|
||||
return nil
|
||||
}
|
||||
if f == nil || !f.Public() {
|
||||
|
||||
7
controllers/api/logger.go
Normal file
7
controllers/api/logger.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package api
|
||||
|
||||
import "git.golem15.com/golem15/summercms/modules/diary"
|
||||
|
||||
// pluginLog is the plugin's logger: its records carry component=journal, so
|
||||
// config/log.yaml can raise or lower them (log.components.journal).
|
||||
var pluginLog = diary.For("journal")
|
||||
@@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -38,7 +37,7 @@ func searchWithEngine(app *backpack.App, r *http.Request, db *gorm.DB, search st
|
||||
}
|
||||
res, err := beachcomber.SearchPage(r.Context(), svc.Engine(), svc.IndexName(&models.Post{}), q)
|
||||
if err != nil {
|
||||
slog.Default().Warn("journal: Typesense search failed, falling back to DB search", "err", err)
|
||||
pluginLog.Warn("journal: Typesense search failed, falling back to DB search", "err", err)
|
||||
return nil, false
|
||||
}
|
||||
ids := make([]uint, 0, len(res.IDs))
|
||||
|
||||
Reference in New Issue
Block a user