Update logger.go

This commit is contained in:
Radmehr Soleimanian 2025-04-03 10:12:16 +03:30 committed by GitHub
parent 64ad9115e2
commit 78fb8e2a6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -164,14 +164,14 @@ func (l *logger) Trace(ctx context.Context, begin time.Time, fc func() (string,
elapsed := time.Since(begin)
switch {
case err != nil && l.LogLevel >= Error && (!errors.Is(err, ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
case err != nil && l.LogLevel <= Error && (!errors.Is(err, ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
sql, rows := fc()
if rows == -1 {
l.Printf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql)
} else {
l.Printf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, rows, sql)
}
case elapsed > l.SlowThreshold && l.SlowThreshold != 0 && l.LogLevel >= Warn:
case elapsed > l.SlowThreshold && l.SlowThreshold != 0 && l.LogLevel <= Warn:
sql, rows := fc()
slowLog := fmt.Sprintf("SLOW SQL >= %v", l.SlowThreshold)
if rows == -1 {
@ -179,7 +179,7 @@ func (l *logger) Trace(ctx context.Context, begin time.Time, fc func() (string,
} else {
l.Printf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql)
}
case l.LogLevel == Info:
case l.LogLevel <= Info:
sql, rows := fc()
if rows == -1 {
l.Printf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql)