mirror of
https://github.com/rclone/rclone.git
synced 2024-12-19 17:34:05 +08:00
abe884e744
Before this change, if rclone is used as a library and logrus is used after a call to rc `sync/bisync`, logging does not work anymore and leads to writing to a closed pipe. This change restores the output correctly. Fixes #8158
23 lines
453 B
Go
23 lines
453 B
Go
// 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()
|
|
logrusSave := logrus.StandardLogger().Out
|
|
buf := &bytes.Buffer{}
|
|
log.SetOutput(buf)
|
|
logrus.SetOutput(buf)
|
|
fun()
|
|
log.SetOutput(logSave)
|
|
logrus.SetOutput(logrusSave)
|
|
return buf.Bytes()
|
|
}
|