feat: support for disable mon logs like sqlx (#3606)

Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
shenbaise9527
2023-10-22 23:00:02 +08:00
committed by GitHub
parent 6286941ebf
commit a242fec5e1
6 changed files with 222 additions and 47 deletions

View File

@@ -9,7 +9,11 @@ import (
const defaultTimeout = time.Second * 3
var slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
var (
slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
logMon = syncx.ForAtomicBool(true)
logSlowMon = syncx.ForAtomicBool(true)
)
type (
options = mopt.ClientOptions
@@ -18,6 +22,17 @@ type (
Option func(opts *options)
)
// DisableLog disables logging of mongo command, includes info and slow logs.
func DisableLog() {
logMon.Set(false)
logSlowMon.Set(false)
}
// DisableInfoLog disables info logging of mongo command, but keeps slow logs.
func DisableInfoLog() {
logMon.Set(false)
}
// SetSlowThreshold sets the slow threshold.
func SetSlowThreshold(threshold time.Duration) {
slowThreshold.Set(threshold)