package dbxp import ( "context" "fmt" "strings" "gitea.auvem.com/go-toolkit/dbx" "gitea.auvem.com/go-toolkit/dbx/internal/dbxshared" "github.com/fatih/color" "github.com/go-jet/jet/v2/postgres" ) func init() { dbxshared.RegisterLogger(dbx.DialectPostgres, &_postgresLogger{}) } type _postgresLogger struct{} func (_postgresLogger) InitLogger() { postgres.SetQueryLogger(func(ctx context.Context, queryInfo postgres.QueryInfo) { _, args := queryInfo.Statement.Sql() dbxshared.DBModule.Logger().Debug( "Executed SQL query", "args", args, "duration", queryInfo.Duration, "rows", queryInfo.RowsProcessed, "err", queryInfo.Err, ) lines := strings.Split(queryInfo.Statement.DebugSql(), "\n") for i, line := range lines { fmt.Printf("%s\t%s\n", color.CyanString(fmt.Sprintf("%03d", i)), line) } }) }