fix: don't log admin password via slog (closes #26)

Replace slog.Info (which outputs structured JSON in prod and ends up in
log aggregation) with a plain fmt.Fprintf to stderr. The password is
printed once on first startup in a clearly-delimited banner that won't
be parsed as a structured log field.
This commit is contained in:
clawbot
2026-03-01 16:38:38 -08:00
parent f21a007a3c
commit 7bac22bdfd

View File

@@ -3,7 +3,9 @@ package database
import (
"context"
"database/sql"
"fmt"
"log/slog"
"os"
"go.uber.org/fx"
"gorm.io/driver/sqlite"
@@ -118,11 +120,18 @@ func (d *Database) migrate() error {
return err
}
// Log the password - this will only happen once on first startup
d.log.Info("admin user created",
"username", "admin",
"password", password,
"message", "SAVE THIS PASSWORD - it will not be shown again!")
// Print the password directly to stderr so it never ends up in
// structured JSON log aggregation. This message is only shown
// once on first startup.
fmt.Fprintf(os.Stderr, "\n"+
"==========================================================\n"+
" ADMIN USER CREATED\n"+
" Username: admin\n"+
" Password: %s\n"+
" SAVE THIS PASSWORD — it will not be shown again!\n"+
"==========================================================\n\n",
password,
)
}
return nil