mirror of
https://github.com/samuelncui/acp.git
synced 2025-12-23 13:15:16 +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)) {},
|
updateProgressBar: func(f func(bar *progressbar.ProgressBar)) {},
|
||||||
updateCopying: func(f func(set map[int64]struct{})) {},
|
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),
|
badDsts: make(map[string]error),
|
||||||
writePipe: make(chan *writeJob, 32),
|
writePipe: make(chan *writeJob, 32),
|
||||||
@@ -84,6 +81,12 @@ func New(ctx context.Context, opts ...Option) (*Copyer, error) {
|
|||||||
c.readingFiles = make(chan struct{}, 1)
|
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)
|
c.running.Add(1)
|
||||||
go wrap(ctx, func() { c.run(ctx) })
|
go wrap(ctx, func() { c.run(ctx) })
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|||||||
11
opt.go
11
opt.go
@@ -5,6 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type source struct {
|
type source struct {
|
||||||
@@ -34,6 +36,8 @@ type option struct {
|
|||||||
|
|
||||||
autoFill bool
|
autoFill bool
|
||||||
autoFillSplitDepth int
|
autoFillSplitDepth int
|
||||||
|
|
||||||
|
logger *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func newOption() *option {
|
func newOption() *option {
|
||||||
@@ -183,3 +187,10 @@ func WithAutoFill(on bool, depth int) Option {
|
|||||||
return o
|
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