Skip to content

Commit

Permalink
bisync: fix output capture restoring the wrong output for logrus
Browse files Browse the repository at this point in the history
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 rclone#8158
  • Loading branch information
dim0x69 authored Nov 12, 2024
1 parent 173b2ac commit abe884e
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions cmd/bisync/bilib/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit abe884e

Please sign in to comment.