mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-14 01:35:31 +00:00
23 lines
674 B
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())
|
|
}
|
|
}
|