完善数据库 SQL 约束与运维治理
This commit is contained in:
@@ -21,6 +21,10 @@ type structuredGormLogger struct {
|
||||
}
|
||||
|
||||
func newGormLogger(logLevel string, logger *zap.Logger) gormLogger.Interface {
|
||||
return newGormLoggerWithThreshold(logLevel, logger, 500*time.Millisecond)
|
||||
}
|
||||
|
||||
func newGormLoggerWithThreshold(logLevel string, logger *zap.Logger, slowThreshold time.Duration) gormLogger.Interface {
|
||||
level := gormLogger.Warn
|
||||
if strings.EqualFold(strings.TrimSpace(logLevel), "debug") {
|
||||
level = gormLogger.Info
|
||||
@@ -28,10 +32,13 @@ func newGormLogger(logLevel string, logger *zap.Logger) gormLogger.Interface {
|
||||
if logger == nil {
|
||||
logger = zap.L()
|
||||
}
|
||||
if slowThreshold <= 0 {
|
||||
slowThreshold = 500 * time.Millisecond
|
||||
}
|
||||
return &structuredGormLogger{
|
||||
logger: logger.With(zap.String("module", "database")),
|
||||
level: level,
|
||||
slowThreshold: 500 * time.Millisecond,
|
||||
slowThreshold: slowThreshold,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user