MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / setTestLogging

Function setTestLogging

base/util_testing.go:636–672  ·  view source on GitHub ↗
(logLevel LogLevel, caller string, logKeys ...LogKey)

Source from the content-addressed store, hash-verified

634}
635
636func setTestLogging(logLevel LogLevel, caller string, logKeys ...LogKey) (teardownFn func()) {
637 if GlobalTestLoggingSet.IsTrue() {
638 // noop, test log level is already set globally
639 return func() {
640 if caller != "" {
641 InfofCtx(context.Background(), KeyAll, "%v: Reset logging", caller)
642 }
643 }
644 }
645
646 logger := consoleLogger.Load()
647 initialLogLevel := LevelInfo
648 initialLogKey := logKeyMask(KeyHTTP)
649
650 // Check that a previous invocation has not forgotten to call teardownFn
651 if *logger.LogLevel != initialLogLevel ||
652 *logger.LogKeyMask != *initialLogKey {
653 panic(fmt.Sprintf("Logging is in an unexpected state! Did a previous test forget to call the teardownFn of SetUpTestLogging?, LogLevel=%s, expected=%s; LogKeyMask=%s, expected=%s", logger.LogLevel, initialLogLevel, logger.LogKeyMask, initialLogKey))
654 }
655 if errorLogger.Load() != nil {
656 panic("Logging is in an expected state, an earlier test possibly needed to call ResetGlobalTestLogging")
657 }
658 logger.LogLevel.Set(logLevel)
659 logger.LogKeyMask.Set(logKeyMask(logKeys...))
660 updateExternalLoggers()
661
662 return func() {
663 logger := consoleLogger.Load()
664 // Return logging to a default state
665 logger.LogLevel.Set(initialLogLevel)
666 logger.LogKeyMask.Set(initialLogKey)
667 updateExternalLoggers()
668 if caller != "" {
669 InfofCtx(context.Background(), KeyAll, "%v: Reset logging", caller)
670 }
671 }
672}
673
674// Make a deep copy from src into dst.
675// Copied from https://github.com/getlantern/deepcopy, commit 7f45deb8130a0acc553242eb0e009e3f6f3d9ce3 (Apache 2 licensed)

Callers 5

TestSetTestLoggingFunction · 0.85
SetUpGlobalTestLoggingFunction · 0.85
SetUpTestLoggingFunction · 0.85
DisableTestLoggingFunction · 0.85
SetUpBenchmarkLoggingFunction · 0.85

Calls 6

logKeyMaskFunction · 0.85
updateExternalLoggersFunction · 0.85
IsTrueMethod · 0.80
LoadMethod · 0.80
InfofCtxFunction · 0.70
SetMethod · 0.45

Tested by 1

TestSetTestLoggingFunction · 0.68