mirror of
https://github.com/rclone/rclone.git
synced 2024-12-01 12:55:19 +01:00
30 lines
615 B
Go
30 lines
615 B
Go
// Package bilib provides common stuff for bisync and bisync_test
|
|
package bilib
|
|
|
|
import (
|
|
"bytes"
|
|
"log"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// CaptureOutput runs a function capturing its output.
|
|
func CaptureOutput(fun func()) []byte {
|
|
logSave := log.Writer()
|
|
logrusSave := logrus.StandardLogger().Writer()
|
|
defer func() {
|
|
err := logrusSave.Close()
|
|
if err != nil {
|
|
fs.Errorf(nil, "error closing logrusSave: %v", err)
|
|
}
|
|
}()
|
|
buf := &bytes.Buffer{}
|
|
log.SetOutput(buf)
|
|
logrus.SetOutput(buf)
|
|
fun()
|
|
log.SetOutput(logSave)
|
|
logrus.SetOutput(logrusSave)
|
|
return buf.Bytes()
|
|
}
|