aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext/gorm_logger.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-10-24 19:12:52 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-10-24 19:12:52 +0200
commitc3ea735c0f03a0827a8e753a5b5adf6e31f4c925 (patch)
treeab2d15625f720858c570e66c00279ccc6cb28ec3 /pkg/ext/gorm_logger.go
parenta9a270ba1e1e9add10d75de3e592efee9728c5b4 (diff)
downloadlens-c3ea735c0f03a0827a8e753a5b5adf6e31f4c925.tar.gz
lens-c3ea735c0f03a0827a8e753a5b5adf6e31f4c925.tar.bz2
lens-c3ea735c0f03a0827a8e753a5b5adf6e31f4c925.zip
feat: Migrate from logrus to slog
Diffstat (limited to 'pkg/ext/gorm_logger.go')
-rw-r--r--pkg/ext/gorm_logger.go28
1 files changed, 11 insertions, 17 deletions
diff --git a/pkg/ext/gorm_logger.go b/pkg/ext/gorm_logger.go
index bfbbb1e..f0ab592 100644
--- a/pkg/ext/gorm_logger.go
+++ b/pkg/ext/gorm_logger.go
@@ -3,15 +3,15 @@ package ext
import (
"context"
"fmt"
+ "log/slog"
"time"
- "github.com/sirupsen/logrus"
"gorm.io/gorm/logger"
"gorm.io/gorm/utils"
)
type Log struct {
- logrus *logrus.Entry
+ logger *slog.Logger
}
func getFullMsg(msg string, data ...interface{}) string {
@@ -24,35 +24,29 @@ func (self *Log) LogMode(_ logger.LogLevel) logger.Interface {
func (self *Log) Info(ctx context.Context, msg string, data ...interface{}) {
fullMsg := getFullMsg(msg, data)
- self.logrus.
- WithContext(ctx).
- Info(fullMsg)
+ self.logger.InfoContext(ctx, fullMsg)
}
func (self *Log) Warn(ctx context.Context, msg string, data ...interface{}) {
fullMsg := getFullMsg(msg, data)
- self.logrus.
- WithContext(ctx).
- Warn(fullMsg)
+ self.logger.
+ WarnContext(ctx, fullMsg)
}
func (self *Log) Error(ctx context.Context, msg string, data ...interface{}) {
fullMsg := getFullMsg(msg, data)
- self.logrus.
- WithContext(ctx).
- Error(fullMsg)
+ self.logger.
+ ErrorContext(ctx, fullMsg)
}
func (self *Log) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), _ error) {
elapsed := time.Since(begin)
sql, _ := fc()
- self.logrus.
- WithContext(ctx).
- WithField("time", elapsed).
- Printf(sql)
+ self.logger.
+ InfoContext(ctx, sql, slog.Duration("elapsed", elapsed))
}
-func Wraplog(log *logrus.Entry) *Log {
+func Wraplog(log *slog.Logger) *Log {
return &Log{
- logrus: log,
+ logger: log,
}
}