diff --git a/acp.go b/acp.go index 959c509..f43ef79 100644 --- a/acp.go +++ b/acp.go @@ -64,9 +64,6 @@ func New(ctx context.Context, opts ...Option) (*Copyer, error) { updateProgressBar: func(f func(bar *progressbar.ProgressBar)) {}, updateCopying: func(f func(set map[int64]struct{})) {}, - logf: func(l logrus.Level, format string, args ...any) { - logrus.StandardLogger().Logf(l, format, args...) - }, badDsts: make(map[string]error), writePipe: make(chan *writeJob, 32), @@ -84,6 +81,12 @@ func New(ctx context.Context, opts ...Option) (*Copyer, error) { c.readingFiles = make(chan struct{}, 1) } + if opt.logger != nil { + c.logf = func(l logrus.Level, format string, args ...any) { opt.logger.Logf(l, format, args...) } + } else { + c.logf = func(l logrus.Level, format string, args ...any) { logrus.StandardLogger().Logf(l, format, args...) } + } + c.running.Add(1) go wrap(ctx, func() { c.run(ctx) }) return c, nil diff --git a/opt.go b/opt.go index f9a0996..cb1fa61 100644 --- a/opt.go +++ b/opt.go @@ -5,6 +5,8 @@ import ( "os" "path" "strings" + + "github.com/sirupsen/logrus" ) type source struct { @@ -34,6 +36,8 @@ type option struct { autoFill bool autoFillSplitDepth int + + logger *logrus.Logger } func newOption() *option { @@ -183,3 +187,10 @@ func WithAutoFill(on bool, depth int) Option { return o } } + +func WithLogger(logger *logrus.Logger) Option { + return func(o *option) *option { + o.logger = logger + return o + } +}