Quiet logging option

This commit is contained in:
Blake Williams
2022-05-15 00:39:32 +10:00
parent c45911a83c
commit 5ff2587777
3 changed files with 25 additions and 2 deletions

View File

@@ -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),
)

View File

@@ -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
View File

@@ -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...)
}
}