Skip to content

Commit

Permalink
update log format
Browse files Browse the repository at this point in the history
  • Loading branch information
wen-templari committed Feb 15, 2024
1 parent b2e3885 commit 5d19cbd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion repo/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/go-sql-driver/mysql"
"github.com/nbtca/saturday/util"
"github.com/qustavo/sqlhooks/v2"
"github.com/sirupsen/logrus"

"github.com/jmoiron/sqlx"
)
Expand All @@ -26,7 +27,11 @@ func (h *Hooks) Before(ctx context.Context, query string, args ...interface{}) (
// After hook will get the timestamp registered on the Before hook and print the elapsed time
func (h *Hooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
begin := ctx.Value("begin").(time.Time)
util.Logger.Debugf("time:%s, query:%s, args:%q", time.Since(begin), query, args)
util.Logger.WithFields(logrus.Fields{
"query": query,
"args": args,
"time": time.Since(begin),
}).Debug("SQL executed")
return ctx, nil
}

Expand Down

0 comments on commit 5d19cbd

Please sign in to comment.