mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 10:05:58 +08:00
feat: merge v3dev into main
This commit is contained in:
@@ -1,17 +1,3 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
@@ -31,11 +17,7 @@ type SqlLogger struct {
|
||||
SlowThreshold time.Duration
|
||||
}
|
||||
|
||||
func NewSqlLogger(
|
||||
logLevel gormLogger.LogLevel,
|
||||
ignoreRecordNotFoundError bool,
|
||||
slowThreshold time.Duration,
|
||||
) *SqlLogger {
|
||||
func NewSqlLogger(logLevel gormLogger.LogLevel, ignoreRecordNotFoundError bool, slowThreshold time.Duration) *SqlLogger {
|
||||
return &SqlLogger{
|
||||
LogLevel: logLevel,
|
||||
IgnoreRecordNotFoundError: ignoreRecordNotFoundError,
|
||||
@@ -70,17 +52,7 @@ func (l *SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql s
|
||||
case err != nil && l.LogLevel >= gormLogger.Error && (!errors.Is(err, gorm.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
|
||||
sql, rows := fc()
|
||||
if rows == -1 {
|
||||
ZError(
|
||||
ctx,
|
||||
"sql exec detail",
|
||||
err,
|
||||
"gorm",
|
||||
gormUtils.FileWithLineNum(),
|
||||
"elapsed time",
|
||||
fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6),
|
||||
"sql",
|
||||
sql,
|
||||
)
|
||||
ZError(ctx, "sql exec detail", err, "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "sql", sql)
|
||||
} else {
|
||||
ZError(ctx, "sql exec detail", err, "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql)
|
||||
}
|
||||
@@ -88,36 +60,14 @@ func (l *SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql s
|
||||
sql, rows := fc()
|
||||
slowLog := fmt.Sprintf("SLOW SQL >= %v", l.SlowThreshold)
|
||||
if rows == -1 {
|
||||
ZWarn(
|
||||
ctx,
|
||||
"sql exec detail",
|
||||
nil,
|
||||
"gorm",
|
||||
gormUtils.FileWithLineNum(),
|
||||
nil,
|
||||
"slow sql",
|
||||
slowLog,
|
||||
"elapsed time",
|
||||
fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6),
|
||||
"sql",
|
||||
sql,
|
||||
)
|
||||
ZWarn(ctx, "sql exec detail", nil, "gorm", gormUtils.FileWithLineNum(), "slow sql", slowLog, "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "sql", sql)
|
||||
} else {
|
||||
ZWarn(ctx, "sql exec detail", nil, "gorm", gormUtils.FileWithLineNum(), nil, "slow sql", slowLog, "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql)
|
||||
ZWarn(ctx, "sql exec detail", nil, "gorm", gormUtils.FileWithLineNum(), "slow sql", slowLog, "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql)
|
||||
}
|
||||
case l.LogLevel == gormLogger.Info:
|
||||
sql, rows := fc()
|
||||
if rows == -1 {
|
||||
ZDebug(
|
||||
ctx,
|
||||
"sql exec detail",
|
||||
"gorm",
|
||||
gormUtils.FileWithLineNum(),
|
||||
"elapsed time",
|
||||
fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6),
|
||||
"sql",
|
||||
sql,
|
||||
)
|
||||
ZDebug(ctx, "sql exec detail", "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "sql", sql)
|
||||
} else {
|
||||
ZDebug(ctx, "sql exec detail", "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user