2021-05-16 16:39:33 +00:00
|
|
|
// Package bilib provides common stuff for bisync and bisync_test
|
|
|
|
package bilib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CaptureOutput runs a function capturing its output.
|
|
|
|
func CaptureOutput(fun func()) []byte {
|
|
|
|
logSave := log.Writer()
|
2024-11-12 11:42:54 +00:00
|
|
|
logrusSave := logrus.StandardLogger().Out
|
2021-05-16 16:39:33 +00:00
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
log.SetOutput(buf)
|
|
|
|
logrus.SetOutput(buf)
|
|
|
|
fun()
|
|
|
|
log.SetOutput(logSave)
|
|
|
|
logrus.SetOutput(logrusSave)
|
|
|
|
return buf.Bytes()
|
|
|
|
}
|