Skip to content

Commit f36bb06

Browse files
cli: Add show-startup-logs flag to reduce startup log verbosity (#1218)
* cli: Add show-startup-logs flag to enable/disable startup logs. This adds the 'show-startup-logs' flag to the tusd server, allowing the user to enable or disable startup logs. This helps the user suppress startup logs as per their preference. Fixes #1216. * Final touches --------- Co-authored-by: Marius Kleidl <[email protected]>
1 parent 7bc9754 commit f36bb06

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

cmd/tusd/cli/composer.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func CreateComposer() {
3737

3838
if Flags.S3Endpoint == "" {
3939
if Flags.S3TransferAcceleration {
40-
stdout.Printf("Using 's3://%s' as S3 bucket for storage with AWS S3 Transfer Acceleration enabled.\n", Flags.S3Bucket)
40+
printStartupLog("Using 's3://%s' as S3 bucket for storage with AWS S3 Transfer Acceleration enabled.\n", Flags.S3Bucket)
4141
} else {
42-
stdout.Printf("Using 's3://%s' as S3 bucket for storage.\n", Flags.S3Bucket)
42+
printStartupLog("Using 's3://%s' as S3 bucket for storage.\n", Flags.S3Bucket)
4343
}
4444
} else {
45-
stdout.Printf("Using '%s/%s' as S3 endpoint and bucket for storage.\n", Flags.S3Endpoint, Flags.S3Bucket)
45+
printStartupLog("Using '%s/%s' as S3 endpoint and bucket for storage.\n", Flags.S3Endpoint, Flags.S3Bucket)
4646
}
4747

4848
s3Client := s3.NewFromConfig(s3Config, func(o *s3.Options) {
@@ -86,7 +86,7 @@ func CreateComposer() {
8686
stderr.Fatalf("Unable to create Google Cloud Storage service: %s\n", err)
8787
}
8888

89-
stdout.Printf("Using 'gcs://%s' as GCS bucket for storage.\n", Flags.GCSBucket)
89+
printStartupLog("Using 'gcs://%s' as GCS bucket for storage.\n", Flags.GCSBucket)
9090

9191
store := gcsstore.New(Flags.GCSBucket, service)
9292
store.ObjectPrefix = Flags.GCSObjectPrefix
@@ -112,7 +112,7 @@ func CreateComposer() {
112112
if azureEndpoint == "" {
113113
azureEndpoint = fmt.Sprintf("https://%s.blob.core.windows.net", accountName)
114114
}
115-
stdout.Printf("Using Azure endpoint %s.\n", azureEndpoint)
115+
printStartupLog("Using Azure endpoint %s.\n", azureEndpoint)
116116

117117
azConfig := &azurestore.AzConfig{
118118
AccountName: accountName,
@@ -141,7 +141,8 @@ func CreateComposer() {
141141
stderr.Fatalf("Unable to make absolute path: %s", err)
142142
}
143143

144-
stdout.Printf("Using '%s' as directory storage.\n", dir)
144+
printStartupLog("Using '%s' as directory storage.\n", dir)
145+
145146
if err := os.MkdirAll(dir, os.FileMode(0774)); err != nil {
146147
stderr.Fatalf("Unable to ensure directory exists: %s", err)
147148
}
@@ -155,5 +156,5 @@ func CreateComposer() {
155156
locker.UseIn(Composer)
156157
}
157158

158-
stdout.Printf("Using %.2fMB as maximum size.\n", float64(Flags.MaxSize)/1024/1024)
159+
printStartupLog("Using %.2fMB as maximum size.\n", float64(Flags.MaxSize)/1024/1024)
159160
}

cmd/tusd/cli/flags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var Flags struct {
7272
PprofMutexProfileRate int
7373
BehindProxy bool
7474
VerboseOutput bool
75+
ShowStartupLogs bool
7576
LogFormat string
7677
S3TransferAcceleration bool
7778
TLSCertFile string
@@ -190,9 +191,10 @@ func ParseFlags() {
190191
f.StringVar(&Flags.PprofPath, "pprof-path", "/debug/pprof/", "Path under which the pprof endpoint will be accessible")
191192
f.IntVar(&Flags.PprofBlockProfileRate, "pprof-block-profile-rate", 0, "Fraction of goroutine blocking events that are reported in the blocking profile")
192193
f.IntVar(&Flags.PprofMutexProfileRate, "pprof-mutex-profile-rate", 0, "Fraction of mutex contention events that are reported in the mutex profile")
193-
f.BoolVar(&Flags.ShowGreeting, "show-greeting", true, "Show the greeting message")
194+
f.BoolVar(&Flags.ShowGreeting, "show-greeting", true, "Show the greeting message for GET requests to the root path")
194195
f.BoolVar(&Flags.ShowVersion, "version", false, "Print tusd version information")
195196
f.BoolVar(&Flags.VerboseOutput, "verbose", true, "Enable verbose logging output")
197+
f.BoolVar(&Flags.ShowStartupLogs, "show-startup-logs", true, "Print details about tusd's configuration during startup")
196198
f.StringVar(&Flags.LogFormat, "log-format", "text", "Logging format (text or json)")
197199
})
198200

cmd/tusd/cli/hooks.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313

1414
func getHookHandler(config *handler.Config) hooks.HookHandler {
1515
if Flags.FileHooksDir != "" {
16-
stdout.Printf("Using '%s' for hooks", Flags.FileHooksDir)
16+
printStartupLog("Using '%s' for hooks", Flags.FileHooksDir)
1717

1818
return &file.FileHook{
1919
Directory: Flags.FileHooksDir,
2020
}
2121
} else if Flags.HttpHooksEndpoint != "" {
22-
stdout.Printf("Using '%s' as the endpoint for hooks", Flags.HttpHooksEndpoint)
22+
printStartupLog("Using '%s' as the endpoint for hooks", Flags.HttpHooksEndpoint)
2323

2424
return &http.HttpHook{
2525
Endpoint: Flags.HttpHooksEndpoint,
@@ -28,7 +28,7 @@ func getHookHandler(config *handler.Config) hooks.HookHandler {
2828
ForwardHeaders: strings.Split(Flags.HttpHooksForwardHeaders, ","),
2929
}
3030
} else if Flags.GrpcHooksEndpoint != "" {
31-
stdout.Printf("Using '%s' as the endpoint for gRPC hooks", Flags.GrpcHooksEndpoint)
31+
printStartupLog("Using '%s' as the endpoint for gRPC hooks", Flags.GrpcHooksEndpoint)
3232

3333
return &grpc.GrpcHook{
3434
Endpoint: Flags.GrpcHooksEndpoint,
@@ -41,7 +41,7 @@ func getHookHandler(config *handler.Config) hooks.HookHandler {
4141
ForwardHeaders: strings.Split(Flags.GrpcHooksForwardHeaders, ","),
4242
}
4343
} else if Flags.PluginHookPath != "" {
44-
stdout.Printf("Using '%s' to load plugin for hooks", Flags.PluginHookPath)
44+
printStartupLog("Using '%s' to load plugin for hooks", Flags.PluginHookPath)
4545

4646
return &plugin.PluginHook{
4747
Path: Flags.PluginHookPath,

cmd/tusd/cli/log.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ func (l logWriter) Write(msg []byte) (int, error) {
6060
l.logger.Print(string(msg))
6161
return len(msg), nil
6262
}
63+
64+
func printStartupLog(msg string, args ...interface{}) {
65+
if !Flags.ShowStartupLogs {
66+
return
67+
}
68+
69+
stdout.Printf(msg, args...)
70+
}

cmd/tusd/cli/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func SetupMetrics(mux *http.ServeMux, handler *handler.Handler) {
2222
prometheus.MustRegister(hooks.MetricsHookInvocationsTotal)
2323
prometheus.MustRegister(prometheuscollector.New(handler.Metrics))
2424

25-
stdout.Printf("Using %s as the metrics path.\n", Flags.MetricsPath)
25+
printStartupLog("Using %s as the metrics path.\n", Flags.MetricsPath)
2626
mux.Handle(Flags.MetricsPath, promhttp.Handler())
2727
}

cmd/tusd/cli/serve.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func Serve() {
5959
enabledHooksString = append(enabledHooksString, string(h))
6060
}
6161

62-
stdout.Printf("Enabled hook events: %s", strings.Join(enabledHooksString, ", "))
62+
printStartupLog("Enabled hook events: %s", strings.Join(enabledHooksString, ", "))
6363

6464
} else {
6565
handler, err = tushandler.NewHandler(config)
@@ -68,20 +68,20 @@ func Serve() {
6868
stderr.Fatalf("Unable to create handler: %s", err)
6969
}
7070

71-
stdout.Printf("Supported tus extensions: %s\n", handler.SupportedExtensions())
71+
printStartupLog("Supported tus extensions: %s\n", handler.SupportedExtensions())
7272

7373
basepath := Flags.Basepath
7474
address := ""
7575

7676
if Flags.HttpSock != "" {
7777
address = Flags.HttpSock
78-
stdout.Printf("Using %s as socket to listen.\n", address)
78+
printStartupLog("Using %s as socket to listen.\n", address)
7979
} else {
8080
address = Flags.HttpHost + ":" + Flags.HttpPort
81-
stdout.Printf("Using %s as address to listen.\n", address)
81+
printStartupLog("Using %s as address to listen.\n", address)
8282
}
8383

84-
stdout.Printf("Using %s as the base path.\n", basepath)
84+
printStartupLog("Using %s as the base path.\n", basepath)
8585

8686
mux := http.NewServeMux()
8787
if basepath == "/" {
@@ -129,7 +129,7 @@ func Serve() {
129129
}
130130

131131
if Flags.HttpSock == "" {
132-
stdout.Printf("You can now upload files to: %s://%s%s", protocol, listener.Addr(), basepath)
132+
printStartupLog("You can now upload files to: %s://%s%s", protocol, listener.Addr(), basepath)
133133
}
134134

135135
serverCtx, cancelServerCtx := context.WithCancelCause(context.Background())

0 commit comments

Comments
 (0)