代码拉取完成,页面将自动刷新
package internal
import (
"context"
"fmt"
"github.com/qiniu/qmgo/options"
"go.mongodb.org/mongo-driver/event"
opt "go.mongodb.org/mongo-driver/mongo/options"
"go.uber.org/zap"
)
// var Mongo = new(mongo)
type mongo struct {
logger *zap.Logger
}
func New(logger *zap.Logger) *mongo {
return &mongo{logger: logger}
}
func (m *mongo) GetClientOptions() []options.ClientOptions {
cmdMonitor := &event.CommandMonitor{
Started: func(ctx context.Context, event *event.CommandStartedEvent) {
m.logger.Info(fmt.Sprintf("[MongoDB][RequestID:%d][database:%s] %s\n", event.RequestID, event.DatabaseName, event.Command), zap.String("business", "mongo"))
},
Succeeded: func(ctx context.Context, event *event.CommandSucceededEvent) {
m.logger.Info(fmt.Sprintf("[MongoDB][RequestID:%d] [%s] %s\n", event.RequestID, event.Duration.String(), event.Reply), zap.String("business", "mongo"))
},
Failed: func(ctx context.Context, event *event.CommandFailedEvent) {
m.logger.Error(fmt.Sprintf("[MongoDB][RequestID:%d] [%s] %s\n", event.RequestID, event.Duration.String(), event.Failure), zap.String("business", "mongo"))
},
}
return []options.ClientOptions{{ClientOptions: &opt.ClientOptions{Monitor: cmdMonitor}}}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。