refactor: unify logging with log/slog
Replace three uncoordinated logging systems (log.Printf, fmt.Fprintf to stderr, fmt.Println warnings) with structured slog calls. 68 log calls migrated: - log.Printf → slog.Error/Warn/Info (45 calls across 5 files) - fmt.Fprintf(os.Stderr) → slog.Error (23 calls in main.go) Kept unchanged: - fmt.Println/Printf for CLI user output (version, banners, import results) - engine.AddLog for TUI-visible ring buffer (monitoring events) Store migration diagnostics demoted to slog.Debug (silent at default info level). HTTP request logging now structured with method/path/ status/duration/ip attributes.
This commit was merged in pull request #110.
This commit is contained in:
+13
-13
@@ -3,7 +3,7 @@ package store
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
@@ -141,44 +141,44 @@ func (d *SQLiteDialect) ResetSequenceOnEmpty(db *sql.DB, table string) {
|
||||
_ = db.QueryRow("SELECT COUNT(*) FROM " + table).Scan(&count) //nolint:errcheck
|
||||
if count == 0 {
|
||||
if _, err := db.Exec("DELETE FROM sqlite_sequence WHERE name=?", table); err != nil {
|
||||
log.Printf("sequence cleanup error: %v", err)
|
||||
slog.Debug("sequence cleanup failed", "table", table, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SQLiteDialect) ImportWipe(tx *sql.Tx) {
|
||||
if _, err := tx.Exec("DELETE FROM sites"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "sites", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM sqlite_sequence WHERE name='sites'"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "sqlite_sequence(sites)", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM alerts"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "alerts", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM sqlite_sequence WHERE name='alerts'"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "sqlite_sequence(alerts)", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM users"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "users", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM sqlite_sequence WHERE name='users'"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "sqlite_sequence(users)", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM maintenance_windows"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "maintenance_windows", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM sqlite_sequence WHERE name='maintenance_windows'"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "sqlite_sequence(maintenance_windows)", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM check_history"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "check_history", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM state_changes"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "state_changes", "err", err)
|
||||
}
|
||||
if _, err := tx.Exec("DELETE FROM alert_health"); err != nil {
|
||||
log.Printf("import wipe error: %v", err)
|
||||
slog.Debug("import wipe failed", "table", "alert_health", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user