Repository: rclone/rclone (language: go)

Issue:
[Bug] CaptureOutput in bilib  (bisync) restores wrong output for logrus 
Regarding CaptureOutput in bilib:

https://github.com/rclone/rclone/blob/b9207e57274cd6e7c488c5bd751a058ba0f8b3b9/cmd/bisync/bilib/output.go#L13

First in logrusSave the InfoLevel-Writer ist stored:

https://github.com/rclone/rclone/blob/b9207e57274cd6e7c488c5bd751a058ba0f8b3b9/cmd/bisync/bilib/output.go#L15

... which is then later restored as the default output destination of the logger:

https://github.com/rclone/rclone/blob/b9207e57274cd6e7c488c5bd751a058ba0f8b3b9/cmd/bisync/bilib/output.go#L27

I think what should be stored instead is the Output of the StandardLogger:

logrusSave := logrus.StandardLogger().Out


Currently, if rclone is used as a library and logrus is used after a call to rc "sync/bisync", logging does not work anymore. It leads to writing to a closed pipe. For example, this leads to a write to a closed pipe:


```go
import (
	logger "github.com/sirupsen/logrus"
)
...


out, status := librclone.RPC("sync/bisync", string(bisyncConfigJson))

if status != 200 {
  logger.Fatal(fmt.Sprintf("sync/bisync failed: %d\n%s", status, out))
}
````


Discussion / hints:

Fix patch:
diff --git a/cmd/bisync/bilib/output.go b/cmd/bisync/bilib/output.go
index ccd85c1259565..c35abde860f0d 100644
--- a/cmd/bisync/bilib/output.go
+++ b/cmd/bisync/bilib/output.go
@@ -5,20 +5,13 @@ 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)
-		}
-	}()
+	logrusSave := logrus.StandardLogger().Out
 	buf := &bytes.Buffer{}
 	log.SetOutput(buf)
 	logrus.SetOutput(buf)


Test patch: