mirror of
https://github.com/samuelncui/acp.git
synced 2025-12-23 05:05:15 +00:00
feat: add logger
This commit is contained in:
9
acp.go
9
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
|
||||
|
||||
11
opt.go
11
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user