From 5d19cbd95603a9a04fdf53bd7fca597cbad16d00 Mon Sep 17 00:00:00 2001 From: ClasWen Date: Thu, 15 Feb 2024 22:19:33 +0800 Subject: [PATCH] update log format --- repo/db.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/repo/db.go b/repo/db.go index d84695b..4d9f779 100644 --- a/repo/db.go +++ b/repo/db.go @@ -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" ) @@ -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 }