mirror of
https://github.com/alist-org/gofakes3.git
synced 2025-12-24 12:58:04 +08:00
Quiet logging option
This commit is contained in:
@@ -36,6 +36,7 @@ type fakeS3Flags struct {
|
||||
noIntegrity bool
|
||||
hostBucket bool
|
||||
autoBucket bool
|
||||
quiet bool
|
||||
|
||||
boltDb string
|
||||
directFsPath string
|
||||
@@ -56,6 +57,9 @@ func (f *fakeS3Flags) attach(flagSet *flag.FlagSet) {
|
||||
flagSet.BoolVar(&f.hostBucket, "hostbucket", false, "If passed, the bucket name will be extracted from the first segment of the hostname, rather than the first part of the URL path.")
|
||||
flagSet.BoolVar(&f.autoBucket, "autobucket", false, "If passed, nonexistent buckets will be created on first use instead of raising an error")
|
||||
|
||||
// Logging
|
||||
flagSet.BoolVar(&f.quiet, "quiet", false, "If passed, log messages are not printed to stderr")
|
||||
|
||||
// Backend specific:
|
||||
flagSet.StringVar(&f.backendKind, "backend", "", "Backend to use to store data (memory, bolt, directfs, fs)")
|
||||
flagSet.StringVar(&f.boltDb, "bolt.db", "locals3.db", "Database path / name when using bolt backend")
|
||||
@@ -220,11 +224,16 @@ func run() error {
|
||||
log.Println("created -initialbucket", values.initialBucket)
|
||||
}
|
||||
|
||||
logger := gofakes3.GlobalLog()
|
||||
if values.quiet {
|
||||
logger = gofakes3.DiscardLog()
|
||||
}
|
||||
|
||||
faker := gofakes3.New(backend,
|
||||
gofakes3.WithIntegrityCheck(!values.noIntegrity),
|
||||
gofakes3.WithTimeSkewLimit(timeSkewLimit),
|
||||
gofakes3.WithTimeSource(timeSource),
|
||||
gofakes3.WithLogger(gofakes3.GlobalLog()),
|
||||
gofakes3.WithLogger(logger),
|
||||
gofakes3.WithHostBucket(values.hostBucket),
|
||||
gofakes3.WithAutoBucket(values.autoBucket),
|
||||
)
|
||||
|
||||
@@ -645,7 +645,7 @@ func (g *GoFakeS3) copyObject(bucket, object string, meta map[string]string, w h
|
||||
}
|
||||
|
||||
source := meta["X-Amz-Copy-Source"]
|
||||
g.log.Print(LogInfo, "COPY:", source)
|
||||
g.log.Print(LogInfo, "COPY:", source, "TO", bucket, object)
|
||||
|
||||
if len(object) > KeySizeLimit {
|
||||
return ResourceError(ErrKeyTooLong, object)
|
||||
|
||||
14
log.go
14
log.go
@@ -109,3 +109,17 @@ func (s *stdLog) Print(level LogLevel, v ...interface{}) {
|
||||
type discardLog struct{}
|
||||
|
||||
func (d discardLog) Print(level LogLevel, v ...interface{}) {}
|
||||
|
||||
func MultiLog(loggers ...Logger) Logger {
|
||||
return &multiLog{loggers}
|
||||
}
|
||||
|
||||
type multiLog struct {
|
||||
loggers []Logger
|
||||
}
|
||||
|
||||
func (m multiLog) Print(level LogLevel, v ...interface{}) {
|
||||
for _, l := range m.loggers {
|
||||
l.Print(level, v...)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user