feat(logging): integrate slog logging with env control and request/sync tracing
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 39s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 39s
- Configure structured slog logger in cmd/server/main.go via LOG_LEVEL and DEBUG env vars - Add HTTP API request logging middleware in internal/api/ with status and duration_ms - Add WebSocket join/leave, event reception, and debounced SQLite flush tracing in docroom - Document LOG_LEVEL and DEBUG settings in .env.example, compose.yaml, and docker-compose.yml
This commit is contained in:
1 parent
177e24fdc8
commit
48fe61fbce
9 files changed
+208
-16
No files matched your search
+17
-10
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"embed"
|
||||
"io/fs"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -23,11 +23,16 @@ var embeddedDist embed.FS
|
||||
func main() {
|
||||
cfg := config.Load()
|
||||
|
||||
log.Printf("🧠 Starting MindSift Server on port %s (DB: %s)", cfg.Port, cfg.DatabasePath)
|
||||
level := cfg.SlogLevel()
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
slog.SetDefault(logger)
|
||||
|
||||
slog.Info("MindSift Server starting", "port", cfg.Port, "log_level", level.String())
|
||||
|
||||
store, err := storage.NewStore(cfg.DatabasePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize storage: %v", err)
|
||||
slog.Error("Failed to initialize storage", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
@@ -35,11 +40,11 @@ func main() {
|
||||
store.SeedSMTPDefaultsFromEnv(cfg.SMTPHost, cfg.SMTPPort, cfg.SMTPUser, cfg.SMTPPass, cfg.SMTPFrom, cfg.SMTPTLS)
|
||||
|
||||
if cfg.DemoMode {
|
||||
log.Printf("🧪 Demo-Modus aktiv (MINDA_DEMO=true): Richte Demo-Benutzer admin/admin und user/user ein...")
|
||||
slog.Info("🧪 Demo-Modus aktiv (MINDA_DEMO=true): Richte Demo-Benutzer admin/admin und user/user ein...")
|
||||
if err := store.EnsureDemoAccounts(); err != nil {
|
||||
log.Printf("⚠️ Fehler beim Anlegen der Demo-Accounts: %v", err)
|
||||
slog.Warn("⚠️ Fehler beim Anlegen der Demo-Accounts", "error", err)
|
||||
} else {
|
||||
log.Printf("✅ Demo-Accounts bereit: admin / admin (Admin-Rolle) und user / user (Standard-Rolle)")
|
||||
slog.Info("✅ Demo-Accounts bereit: admin / admin (Admin-Rolle) und user / user (Standard-Rolle)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +52,8 @@ func main() {
|
||||
|
||||
staticFS, err := fs.Sub(embeddedDist, "dist")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to mount embedded dist filesystem: %v", err)
|
||||
slog.Error("Failed to mount embedded dist filesystem", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
srv := api.NewServer(cfg, store, wsHub, staticFS)
|
||||
@@ -61,9 +67,10 @@ func main() {
|
||||
}
|
||||
|
||||
go func() {
|
||||
log.Printf("✨ MindSift ready at http://0.0.0.0:%s", cfg.Port)
|
||||
slog.Info("✨ MindSift ready", "url", "http://0.0.0.0:"+cfg.Port)
|
||||
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("HTTP server error: %v", err)
|
||||
slog.Error("HTTP server error", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -71,7 +78,7 @@ func main() {
|
||||
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
||||
<-stop
|
||||
|
||||
log.Println("Shutting down MindSift server gracefully...")
|
||||
slog.Info("Shutting down MindSift server gracefully...")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_ = httpServer.Shutdown(ctx)
|
||||
|
||||
Reference in new issue
Block a user