Skip to content

Commit

Permalink
Merge pull request #11 from hipeople/debug-log
Browse files Browse the repository at this point in the history
Set log level to debug
  • Loading branch information
sentriz authored Nov 14, 2023
2 parents 56c9c80 + 4992649 commit 00fefca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type WithContext struct {
func (ctx *WithContext) Exec(sql string, params ...interface{}) (stdsql.Result, error) {
start := time.Now()
result, err := ctx.DB.ExecContext(ctx.Context, sql, params...)
slog.InfoContext(ctx.Context, "Executed SQL query", "sql", sql, "took", time.Since(start))
slog.DebugContext(ctx.Context, "Executed SQL query", "sql", sql, "took", time.Since(start))

return result, err
}
Expand All @@ -28,7 +28,7 @@ func (ctx *WithContext) Exec(sql string, params ...interface{}) (stdsql.Result,
func (ctx *WithContext) Query(sql string, params ...interface{}) (*stdsql.Rows, error) {
start := time.Now()
result, err := ctx.DB.QueryContext(ctx.Context, sql, params...)
slog.InfoContext(ctx.Context, "Ran SQL query", "sql", sql, "took", time.Since(start))
slog.DebugContext(ctx.Context, "Ran SQL query", "sql", sql, "took", time.Since(start))

return result, err
}
Expand Down
4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (db *DB) Ping() error {
func (db *DB) Exec(sql string, params ...interface{}) (stdsql.Result, error) {
start := time.Now()
result, error := db.Client.Exec(sql, params...)
slog.Info("Executed SQL query", "sql", sql, "took", time.Since(start))
slog.Debug("Executed SQL query", "sql", sql, "took", time.Since(start))
return result, error
}

Expand All @@ -36,7 +36,7 @@ func (db *DB) Exec(sql string, params ...interface{}) (stdsql.Result, error) {
func (db *DB) Query(sql string, params ...interface{}) (*stdsql.Rows, error) {
start := time.Now()
result, error := db.Client.Query(sql, params...)
slog.Info("Ran SQL query", "sql", sql, "took", time.Since(start))
slog.Debug("Ran SQL query", "sql", sql, "took", time.Since(start))
return result, error
}

Expand Down
8 changes: 4 additions & 4 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ type Tx struct {
func (tx *Tx) Exec(sql string, params ...interface{}) (stdsql.Result, error) {
start := time.Now()
result, err := tx.Client.ExecContext(tx.Context, sql, params...)
slog.InfoContext(tx.Context, "Executed SQL query", "sql", sql, "took", time.Since(start))
slog.DebugContext(tx.Context, "Executed SQL query", "sql", sql, "took", time.Since(start))
return result, err
}

// Execute any SQL query on the transaction client. Returns sql.Rows.
func (tx *Tx) Query(sql string, params ...interface{}) (*stdsql.Rows, error) {
start := time.Now()
result, err := tx.Client.QueryContext(tx.Context, sql, params...)
slog.InfoContext(tx.Context, "Ran SQL query", "sql", sql, "took", time.Since(start))
slog.DebugContext(tx.Context, "Ran SQL query", "sql", sql, "took", time.Since(start))
return result, err
}

// Commit the transaction.
func (tx *Tx) Commit() error {
slog.InfoContext(tx.Context, "Committing")
slog.DebugContext(tx.Context, "Committing")
return tx.Client.Commit()
}

// Rollback the transaction.
func (tx *Tx) Rollback() error {
slog.InfoContext(tx.Context, "Rolling back")
slog.DebugContext(tx.Context, "Rolling back")
return tx.Client.Rollback()
}

Expand Down

0 comments on commit 00fefca

Please sign in to comment.