mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
perf: hide mongodb passwords when printing logs
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"mayfly-go/pkg/model"
|
"mayfly-go/pkg/model"
|
||||||
"mayfly-go/pkg/utils"
|
"mayfly-go/pkg/utils"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
@@ -95,7 +96,7 @@ func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client {
|
|||||||
|
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
//mongo客户端连接缓存,指定时间内没有访问则会被关闭
|
// mongo客户端连接缓存,指定时间内没有访问则会被关闭
|
||||||
var mongoCliCache = cache.NewTimedCache(constant.MongoConnExpireTime, 5*time.Second).
|
var mongoCliCache = cache.NewTimedCache(constant.MongoConnExpireTime, 5*time.Second).
|
||||||
WithUpdateAccessTime(true).
|
WithUpdateAccessTime(true).
|
||||||
OnEvicted(func(key interface{}, value interface{}) {
|
OnEvicted(func(key interface{}, value interface{}) {
|
||||||
@@ -177,7 +178,10 @@ func connect(me *entity.Mongo) (*MongoInstance, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
global.Log.Infof("连接mongo: %s", me.Uri)
|
global.Log.Infof("连接mongo: %s", func(str string) string {
|
||||||
|
reg := regexp.MustCompile(`(^mongodb://.+?:)(.+)(@.+$)`)
|
||||||
|
return reg.ReplaceAllString(str, `${1}****${3}`)
|
||||||
|
}(me.Uri))
|
||||||
mongoInstance.Cli = client
|
mongoInstance.Cli = client
|
||||||
return mongoInstance, err
|
return mongoInstance, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user