Skip to main content

Logging

ant.WithLogger logs statements through log/slog. Values stay out of the logs unless you opt in, and there's a test that proves it.

Turning it on​

logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))

db, err := ant.Open[AppDB](ctx, postgres.Dialect, dsn, ant.WithLogger(logger))

Statements log at debug, slow ones at warning, and failures at error.

Slow queries​

db, err := ant.Open[AppDB](ctx, postgres.Dialect, dsn,
ant.WithLogger(logger, ant.SlowThreshold(200*time.Millisecond)),
)

Values​

ant.LogValues puts values in logs, for development.

db, err := ant.Open[AppDB](ctx, postgres.Dialect, dsn,
ant.WithLogger(logger, ant.LogValues()),
)

.Sensitive() keeps a column out even then, on inserts, updates, Set, and conditions. It logs as [redacted].

type Account struct {
ID int64
Password string
}

func (Account) Configure(b *ant.ModelBuilder[Account]) {
b.Column(&A.Password).Sensitive()
}

var A = ant.Fields[Account]()
Limits

ant.SQL arguments aren't covered by .Sensitive(), since ant can't tell which column they belong to. And a database error's message can quote a value, so don't return err.Error() to users.