Skip to content

Commit

Permalink
Final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Nov 28, 2024
1 parent 240ebed commit 6feed72
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
18 changes: 11 additions & 7 deletions cmd/tusd/cli/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func CreateComposer() {

if Flags.S3Endpoint == "" {
if Flags.S3TransferAcceleration {
printStartupLogLine("Using 's3://%s' as S3 bucket for storage with AWS S3 Transfer Acceleration enabled.\n", Flags.S3Bucket)
printStartupLog("Using 's3://%s' as S3 bucket for storage with AWS S3 Transfer Acceleration enabled.\n", Flags.S3Bucket)
} else {
printStartupLogLine("Using 's3://%s' as S3 bucket for storage.\n", Flags.S3Bucket)
printStartupLog("Using 's3://%s' as S3 bucket for storage.\n", Flags.S3Bucket)
}
} else {
printStartupLogLine("Using '%s/%s' as S3 endpoint and bucket for storage.\n", Flags.S3Endpoint, Flags.S3Bucket)
printStartupLog("Using '%s/%s' as S3 endpoint and bucket for storage.\n", Flags.S3Endpoint, Flags.S3Bucket)
}

s3Client := s3.NewFromConfig(s3Config, func(o *s3.Options) {
Expand Down Expand Up @@ -85,7 +85,8 @@ func CreateComposer() {
if err != nil {
stderr.Fatalf("Unable to create Google Cloud Storage service: %s\n", err)
}
printStartupLogLine("Using 'gcs://%s' as GCS bucket for storage.\n", Flags.GCSBucket)

printStartupLog("Using 'gcs://%s' as GCS bucket for storage.\n", Flags.GCSBucket)

store := gcsstore.New(Flags.GCSBucket, service)
store.ObjectPrefix = Flags.GCSObjectPrefix
Expand All @@ -111,7 +112,7 @@ func CreateComposer() {
if azureEndpoint == "" {
azureEndpoint = fmt.Sprintf("https://%s.blob.core.windows.net", accountName)
}
printStartupLogLine("Using Azure endpoint %s.\n", azureEndpoint)
printStartupLog("Using Azure endpoint %s.\n", azureEndpoint)

azConfig := &azurestore.AzConfig{
AccountName: accountName,
Expand Down Expand Up @@ -139,7 +140,9 @@ func CreateComposer() {
if err != nil {
stderr.Fatalf("Unable to make absolute path: %s", err)
}
printStartupLogLine("Using '%s' as directory storage.\n", dir)

printStartupLog("Using '%s' as directory storage.\n", dir)

if err := os.MkdirAll(dir, os.FileMode(0774)); err != nil {
stderr.Fatalf("Unable to ensure directory exists: %s", err)
}
Expand All @@ -152,5 +155,6 @@ func CreateComposer() {
locker.HolderPollInterval = Flags.FilelockHolderPollInterval
locker.UseIn(Composer)
}
printStartupLogLine("Using %.2fMB as maximum size.\n", float64(Flags.MaxSize)/1024/1024)

printStartupLog("Using %.2fMB as maximum size.\n", float64(Flags.MaxSize)/1024/1024)
}
4 changes: 2 additions & 2 deletions cmd/tusd/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ func ParseFlags() {
f.StringVar(&Flags.PprofPath, "pprof-path", "/debug/pprof/", "Path under which the pprof endpoint will be accessible")
f.IntVar(&Flags.PprofBlockProfileRate, "pprof-block-profile-rate", 0, "Fraction of goroutine blocking events that are reported in the blocking profile")
f.IntVar(&Flags.PprofMutexProfileRate, "pprof-mutex-profile-rate", 0, "Fraction of mutex contention events that are reported in the mutex profile")
f.BoolVar(&Flags.ShowGreeting, "show-greeting", true, "Show the greeting message")
f.BoolVar(&Flags.ShowGreeting, "show-greeting", true, "Show the greeting message for GET requests to the root path")
f.BoolVar(&Flags.ShowVersion, "version", false, "Print tusd version information")
f.BoolVar(&Flags.VerboseOutput, "verbose", true, "Enable verbose logging output")
f.BoolVar(&Flags.ShowStartupLogs, "show-startup-logs", true, "Show the startup logs")
f.BoolVar(&Flags.ShowStartupLogs, "show-startup-logs", true, "Print details about tusd's configuration during startup")
f.StringVar(&Flags.LogFormat, "log-format", "text", "Logging format (text or json)")
})

Expand Down
8 changes: 4 additions & 4 deletions cmd/tusd/cli/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (

func getHookHandler(config *handler.Config) hooks.HookHandler {
if Flags.FileHooksDir != "" {
printStartupLogLine("Using '%s' for hooks", Flags.FileHooksDir)
printStartupLog("Using '%s' for hooks", Flags.FileHooksDir)

return &file.FileHook{
Directory: Flags.FileHooksDir,
}
} else if Flags.HttpHooksEndpoint != "" {
printStartupLogLine("Using '%s' as the endpoint for hooks", Flags.HttpHooksEndpoint)
printStartupLog("Using '%s' as the endpoint for hooks", Flags.HttpHooksEndpoint)

return &http.HttpHook{
Endpoint: Flags.HttpHooksEndpoint,
Expand All @@ -28,7 +28,7 @@ func getHookHandler(config *handler.Config) hooks.HookHandler {
ForwardHeaders: strings.Split(Flags.HttpHooksForwardHeaders, ","),
}
} else if Flags.GrpcHooksEndpoint != "" {
printStartupLogLine("Using '%s' as the endpoint for gRPC hooks", Flags.GrpcHooksEndpoint)
printStartupLog("Using '%s' as the endpoint for gRPC hooks", Flags.GrpcHooksEndpoint)

return &grpc.GrpcHook{
Endpoint: Flags.GrpcHooksEndpoint,
Expand All @@ -41,7 +41,7 @@ func getHookHandler(config *handler.Config) hooks.HookHandler {
ForwardHeaders: strings.Split(Flags.GrpcHooksForwardHeaders, ","),
}
} else if Flags.PluginHookPath != "" {
printStartupLogLine("Using '%s' to load plugin for hooks", Flags.PluginHookPath)
printStartupLog("Using '%s' to load plugin for hooks", Flags.PluginHookPath)

return &plugin.PluginHook{
Path: Flags.PluginHookPath,
Expand Down
10 changes: 6 additions & 4 deletions cmd/tusd/cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func SetupStructuredLogger() {
if Flags.VerboseOutput {
level = slog.LevelDebug
}

replaceAttrFunc := func(groups []string, a slog.Attr) slog.Attr {
// Remove time attribute, because that is handled by the logger
if a.Key == slog.TimeKey {
Expand Down Expand Up @@ -60,9 +61,10 @@ func (l logWriter) Write(msg []byte) (int, error) {
return len(msg), nil
}

func printStartupLogLine(msg string, args ...interface{}) {
// Check if the flag allows startup logs
if Flags.ShowStartupLogs {
stdout.Printf("[STARTUP] "+msg, args...)
func printStartupLog(msg string, args ...interface{}) {
if !Flags.ShowStartupLogs {
return
}

stdout.Printf(msg, args...)
}
2 changes: 1 addition & 1 deletion cmd/tusd/cli/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ func SetupMetrics(mux *http.ServeMux, handler *handler.Handler) {
prometheus.MustRegister(hooks.MetricsHookInvocationsTotal)
prometheus.MustRegister(prometheuscollector.New(handler.Metrics))

printStartupLogLine("Using %s as the metrics path.\n", Flags.MetricsPath)
printStartupLog("Using %s as the metrics path.\n", Flags.MetricsPath)
mux.Handle(Flags.MetricsPath, promhttp.Handler())
}
16 changes: 10 additions & 6 deletions cmd/tusd/cli/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,31 @@ func Serve() {
for _, h := range Flags.EnabledHooks {
enabledHooksString = append(enabledHooksString, string(h))
}
printStartupLogLine("Enabled hook events: %s", strings.Join(enabledHooksString, ", "))

printStartupLog("Enabled hook events: %s", strings.Join(enabledHooksString, ", "))

} else {
handler, err = tushandler.NewHandler(config)
}
if err != nil {
stderr.Fatalf("Unable to create handler: %s", err)
}
printStartupLogLine("Supported tus extensions: %s\n", handler.SupportedExtensions())

printStartupLog("Supported tus extensions: %s\n", handler.SupportedExtensions())

basepath := Flags.Basepath
address := ""

if Flags.HttpSock != "" {
address = Flags.HttpSock
printStartupLogLine("Using %s as socket to listen.\n", address)
printStartupLog("Using %s as socket to listen.\n", address)
} else {
address = Flags.HttpHost + ":" + Flags.HttpPort
printStartupLogLine("Using %s as address to listen.\n", address)
printStartupLog("Using %s as address to listen.\n", address)
}
printStartupLogLine("Using %s as the base path.\n", basepath)

printStartupLog("Using %s as the base path.\n", basepath)

mux := http.NewServeMux()
if basepath == "/" {
// If the basepath is set to the root path, only install the tusd handler
Expand Down Expand Up @@ -125,7 +129,7 @@ func Serve() {
}

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

serverCtx, cancelServerCtx := context.WithCancelCause(context.Background())
Expand Down

0 comments on commit 6feed72

Please sign in to comment.