mirror of
https://github.com/rclone/rclone.git
synced 2024-11-21 16:03:29 +01:00
bisync: fix output capture restoring the wrong output for logrus
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
This commit is contained in:
parent
173b2ac956
commit
abe884e744
@ -5,20 +5,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CaptureOutput runs a function capturing its output.
|
// CaptureOutput runs a function capturing its output.
|
||||||
func CaptureOutput(fun func()) []byte {
|
func CaptureOutput(fun func()) []byte {
|
||||||
logSave := log.Writer()
|
logSave := log.Writer()
|
||||||
logrusSave := logrus.StandardLogger().Writer()
|
logrusSave := logrus.StandardLogger().Out
|
||||||
defer func() {
|
|
||||||
err := logrusSave.Close()
|
|
||||||
if err != nil {
|
|
||||||
fs.Errorf(nil, "error closing logrusSave: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
log.SetOutput(buf)
|
log.SetOutput(buf)
|
||||||
logrus.SetOutput(buf)
|
logrus.SetOutput(buf)
|
||||||
|
Loading…
Reference in New Issue
Block a user