diff --git a/cmd/gofakes3/main.go b/cmd/gofakes3/main.go index 8629994..87b33e6 100644 --- a/cmd/gofakes3/main.go +++ b/cmd/gofakes3/main.go @@ -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), ) diff --git a/gofakes3.go b/gofakes3.go index 135299f..a8c0714 100644 --- a/gofakes3.go +++ b/gofakes3.go @@ -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) diff --git a/log.go b/log.go index 178726f..1de3496 100644 --- a/log.go +++ b/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...) + } +}