Skip to content

Commit

Permalink
feat: configurable duration for slow queries
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Feb 4, 2025
1 parent 4a38e48 commit c6c5e85
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gorm/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ type Logger interface {
}

type Config struct {
// SlowThreshold in nanoseconds
SlowThreshold int64
SlowThreshold time.Duration
Colorful bool
IgnoreRecordNotFoundError bool
LogLevel int
Expand Down Expand Up @@ -91,7 +90,7 @@ func NewSqlLogger(logger *commons.SlogLogger) logger.Interface {
return &SqlLogger{
Config: Config{
Colorful: true,
SlowThreshold: time.Second.Nanoseconds(),
SlowThreshold: properties.Duration(time.Second, "log.db.slowThreshold"),
IgnoreRecordNotFoundError: true,
},
Logger: logger,
Expand Down Expand Up @@ -122,9 +121,10 @@ func (l *SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (strin
return
}

elapsed := int64(time.Since(begin).Nanoseconds())
elapsed := time.Since(begin)
msg := ""
level := l.baseLevel

switch {
case err != nil && (!errors.Is(err, gorm.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
sql, rows := fc()
Expand Down

0 comments on commit c6c5e85

Please sign in to comment.