Files
backrest/internal/orchestrator/repo/logging.go

23 lines
674 B
Go

package repo
import (
"context"
"github.com/garethgeorge/backrest/internal/ioutil"
"github.com/garethgeorge/backrest/internal/orchestrator/logging"
"github.com/garethgeorge/backrest/pkg/restic"
)
// pipeResticLogsToWriter sets the restic logger to write to the provided writer.
// returns a new context with the logger set and a function to flush the logs.
func forwardResticLogs(ctx context.Context) (context.Context, func()) {
writer := logging.WriterFromContext(ctx)
if writer == nil {
return ctx, func() {}
}
capture := ioutil.NewOutputCapturer(64 * 1024)
return restic.ContextWithLogger(ctx, capture), func() {
_, _ = writer.Write(capture.Bytes())
}
}