Merge pull request #357 from versity/ben/quiet_logging

feat: add quiet option to silence request log output
This commit is contained in:
Ben McClelland
2023-12-26 10:28:30 -08:00
committed by GitHub
2 changed files with 19 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ var (
logWebhookURL string
accessLog string
debug bool
quiet bool
iamDir string
ldapURL, ldapBindDN, ldapPassword string
ldapQueryBase, ldapObjClasses string
@@ -176,6 +177,12 @@ func initFlags() []cli.Flag {
Usage: "enable debug output",
Destination: &debug,
},
&cli.BoolFlag{
Name: "quiet",
Usage: "silence stdout request logging output",
Destination: &quiet,
Aliases: []string{"q"},
},
&cli.StringFlag{
Name: "access-log",
Usage: "enable server access logging to specified file",
@@ -348,6 +355,9 @@ func runGateway(ctx context.Context, be backend.Backend) error {
if admPort == "" {
opts = append(opts, s3api.WithAdminServer())
}
if quiet {
opts = append(opts, s3api.WithQuiet())
}
admApp := fiber.New(fiber.Config{
AppName: "versitygw",

View File

@@ -32,6 +32,7 @@ type S3ApiServer struct {
router *S3ApiRouter
port string
cert *tls.Certificate
quiet bool
debug bool
}
@@ -48,7 +49,9 @@ func New(app *fiber.App, be backend.Backend, root middlewares.RootUserConfig, po
}
// Logging middlewares
app.Use(logger.New())
if !server.quiet {
app.Use(logger.New())
}
app.Use(middlewares.DecodeURL(l))
app.Use(middlewares.RequestLogger(server.debug))
@@ -80,6 +83,11 @@ func WithDebug() Option {
return func(s *S3ApiServer) { s.debug = true }
}
// WithQuiet silences default logging output
func WithQuiet() Option {
return func(s *S3ApiServer) { s.quiet = true }
}
func (sa *S3ApiServer) Serve() (err error) {
if sa.cert != nil {
return sa.app.ListenTLSWithCertificate(sa.port, *sa.cert)