refactor(log): split location into package/file/class/method, auto-derived

Per the log schema: 'package' is the Go package (absent on
Python-emitted lines), 'file' the Go/Python source basename, 'class' the
Go receiver or Python class (omitted when there is none -- free
functions no longer masquerade under a package-as-class), 'method' the
emitting function. applog.App() now takes no arguments and derives all
of it from runtime.Caller, so labels can never drift from the code; the
manual http/wrapper emitters and forwarded wrapper.py lines (file=
wrapper.py, no package) carry the same fields.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-04 19:59:48 +02:00
parent 6effb79097
commit 10cdc4176a
14 changed files with 91 additions and 47 deletions

View File

@@ -93,12 +93,12 @@ func main() {
outPath := "../docs/DATABASE.md"
must(os.WriteFile(outPath, []byte(b.String()), 0644))
applog.App("main", "main").Info("wrote schema doc", "path", outPath)
applog.App().Info("wrote schema doc", "path", outPath)
}
func must(err error) {
if err != nil {
applog.App("main", "must").Error("dumpschema failed", "error", err)
applog.App().Error("dumpschema failed", "error", err)
os.Exit(1)
}
}

View File

@@ -24,7 +24,7 @@ import (
// structured replacement for log.Fatalf, so even startup failures come
// out as JSON lines.
func fatal(msg string, err error) {
applog.App("main", "fatal").Error(msg, "error", err)
applog.App().Error(msg, "error", err)
os.Exit(1)
}
@@ -103,17 +103,17 @@ func main() {
httpServer := &http.Server{Addr: envCfg.BackendAddr, Handler: server.Router()}
go func() {
applog.App("main", "main").Info("geniusrund listening", "addr", envCfg.BackendAddr)
applog.App().Info("geniusrund listening", "addr", envCfg.BackendAddr)
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
fatal("http server", err)
}
}()
<-ctx.Done()
applog.App("main", "main").Info("shutting down")
applog.App().Info("shutting down")
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := httpServer.Shutdown(shutdownCtx); err != nil {
applog.App("main", "main").Error("http server shutdown", "error", err)
applog.App().Error("http server shutdown", "error", err)
}
}

View File

@@ -243,7 +243,7 @@ func must(err error) {
// fatal logs through the application JSON logger and exits -- the
// structured replacement for log.Fatal.
func fatal(msg string, err error) {
applog.App("main", "fatal").Error(msg, "error", err)
applog.App().Error(msg, "error", err)
os.Exit(1)
}
@@ -255,7 +255,7 @@ func mustFindKindID(ctx context.Context, db *store.DB, userID int64, name string
return k.ID
}
}
applog.App("main", "mustFindKindID").Error("no workout kind with that name for the seeded user (did ProvisionUser seed the taxonomy?)", "kind", name)
applog.App().Error("no workout kind with that name for the seeded user (did ProvisionUser seed the taxonomy?)", "kind", name)
os.Exit(1)
return 0
}