MCPcopy
hub / github.com/rclone/rclone / CaptureOutput

Function CaptureOutput

cmd/bisync/bilib/output.go:13–30  ·  view source on GitHub ↗

CaptureOutput runs a function capturing its output at log level INFO.

(fun func())

Source from the content-addressed store, hash-verified

11
12// CaptureOutput runs a function capturing its output at log level INFO.
13func CaptureOutput(fun func()) []byte {
14 var mu sync.Mutex
15 buf := &bytes.Buffer{}
16 oldLevel := log.Handler.SetLevel(slog.LevelInfo)
17 log.Handler.SetOutput(func(level slog.Level, text string) {
18 mu.Lock()
19 defer mu.Unlock()
20 buf.WriteString(text)
21 })
22 defer func() {
23 log.Handler.ResetOutput()
24 log.Handler.SetLevel(oldLevel)
25 }()
26 fun()
27 mu.Lock()
28 defer mu.Unlock()
29 return buf.Bytes()
30}

Callers 6

rcBisyncFunction · 0.92
runBisyncMethod · 0.92
testNothingToTransferFunction · 0.92
testCheckFunction · 0.92
testCheckSumFunction · 0.92

Calls 7

ResetOutputMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
WriteStringMethod · 0.65
SetLevelMethod · 0.45
SetOutputMethod · 0.45
BytesMethod · 0.45

Tested by 5

runBisyncMethod · 0.74
testNothingToTransferFunction · 0.74
testCheckFunction · 0.74
testCheckSumFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…