chore(runtime): silence gin per-route logs and emit env config banner at startup

Two unrelated startup-noise fixes bundled because they share one file
(internal/runtime/startup.go) and one motivation (make the boot log
useful again).

Gin per-route spam
------------------
With ~150 registered routes, DebugMode prints one "[GIN-debug] METHOD
path --> handler" line per route, drowning out everything else. Override
gin.DebugPrintRouteFunc to a counter and gin.DebugPrintFunc to route
through the structured logger. A single "[gin] registered N routes"
summary prints once router build is complete. DebugMode behaviour
otherwise (panic recovery, runtime warnings) is preserved.

Env config banner
-----------------
Operators had no easy way to confirm SYSTEM_AES_KEY (or any other
critical env) was actually loaded — getting the byte length wrong is
particularly silent: utils.GetAESKey() returns nil for anything other
than exactly 32 bytes, which simply disables encryption.

LogStartupEnv prints one line per curated env var (security + DB +
storage + redis), with sensitive values redacted as "set (N chars)"
and unset values as "<unset>". Followed by targeted footgun warnings —
the AES-256 length check fires loudly when SYSTEM_AES_KEY is set but
wrong-length.

Both helpers are called from cmd/server and cmd/desktop. The env banner
runs before container.BuildContainer so it prints even if DB / storage
init fails.
This commit is contained in:
wizardchen
2026-05-17 14:42:24 +08:00
committed by lyingbug
parent dc634e863a
commit 31d5566a50
3 changed files with 163 additions and 0 deletions
+7
View File
@@ -47,6 +47,12 @@ func main() {
} else {
gin.SetMode(gin.DebugMode)
}
// Mute Gin's per-route registration spam (one line per route × ~150
// routes) — replaced by a single summary printed after router build.
runtime.SilenceGinRouteSpam()
// Print the env banner before container build so operators see what
// config landed even when DB / storage init fails.
runtime.LogStartupEnv(context.Background())
// Build dependency injection container
c := container.BuildContainer(runtime.GetContainer())
@@ -109,6 +115,7 @@ func main() {
done()
}()
runtime.LogGinRouteCount(context.Background())
logger.Infof(context.Background(), "Server is running at %s", addr)
if err := server.Serve(listener); err != nil && err != http.ErrServerClosed {
return fmt.Errorf("server error: %v", err)