Skip to content

Commit

Permalink
cmd/...: setup zap as the first thing
Browse files Browse the repository at this point in the history
zap.L().Fatal doesn't log anything to output, unless you've reached the
point where you have setup zap itself. Let's setup zap to do some
logging at the very least.

Change-Id: Iac9347c6920798d573d79588fb416ef4cb862920
  • Loading branch information
egonelbre authored and andriikotko committed Mar 15, 2024
1 parent 50d8aaa commit 2108a62
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/certificates/main.go
Expand Up @@ -91,6 +91,9 @@ func cmdRun(cmd *cobra.Command, args []string) error {
}

func main() {
logger, _, _ := process.NewLogger("certificates")
zap.ReplaceGlobals(logger)

defaultConfDir := fpath.ApplicationDir("storj", "cert-signing")
defaultIdentityDir := fpath.ApplicationDir("storj", "identity", "certificates")
cfgstruct.SetupFlag(zap.L(), rootCmd, &confDir, "config-dir", defaultConfDir, "main directory for certificates configuration")
Expand Down
3 changes: 3 additions & 0 deletions cmd/crashcollect/main.go
Expand Up @@ -24,6 +24,9 @@ type Config struct {
}

func main() {
logger, _, _ := process.NewLogger("crashcollect")
zap.ReplaceGlobals(logger)

rootCmd := &cobra.Command{
Use: "crashcollect",
Short: "Crash collect service",
Expand Down
3 changes: 3 additions & 0 deletions cmd/identity/main.go
Expand Up @@ -81,6 +81,9 @@ func init() {
}

func main() {
logger, _, _ := process.NewLogger("identity")
zap.ReplaceGlobals(logger)

process.Exec(rootCmd)
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/metric-receiver/main.go
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"go.uber.org/zap"

"storj.io/common/process"
"storj.io/common/telemetry"
Expand All @@ -18,6 +19,9 @@ var (
)

func main() {
logger, _, _ := process.NewLogger("metric-receiver")
zap.ReplaceGlobals(logger)

process.Exec(&cobra.Command{
Use: "metric-receiver",
Short: "receive metrics",
Expand Down
3 changes: 3 additions & 0 deletions cmd/multinode/main.go
Expand Up @@ -88,6 +88,9 @@ $ cat nodes.json | multinode add -
)

func main() {
logger, _, _ := process.NewLogger("multinode")
zap.ReplaceGlobals(logger)

process.ExecCustomDebug(rootCmd)
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/satellite/main.go
Expand Up @@ -1133,5 +1133,8 @@ func cmdFixLastNets(cmd *cobra.Command, _ []string) (err error) {
}

func main() {
logger, _, _ := process.NewLogger("satellite")
zap.ReplaceGlobals(logger)

process.ExecCustomDebug(rootCmd)
}
3 changes: 3 additions & 0 deletions cmd/storagenode-updater/main.go
Expand Up @@ -13,6 +13,9 @@ import (
)

func main() {
logger, _, _ := process.NewLogger("storagenode-updater")
zap.ReplaceGlobals(logger)

loggerFunc := func(logger *zap.Logger) *zap.Logger {
return logger.With(zap.String("Process", updaterServiceName))
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/storagenode-updater/main_windows.go
Expand Up @@ -28,6 +28,9 @@ func isRunCmd() bool {
}

func main() {
logger, _, _ := process.NewLogger("storagenode-updater")
zap.ReplaceGlobals(logger)

isService, err := svc.IsWindowsService()
if err != nil {
zap.L().Fatal("Failed to determine if session is interactive.", zap.Error(err))
Expand Down
5 changes: 4 additions & 1 deletion cmd/storagenode/main.go
Expand Up @@ -15,6 +15,9 @@ import (
)

func main() {
logger, _, _ := process.NewLogger("storagenode")
zap.ReplaceGlobals(logger.With(zap.String("Process", "storagenode")))

process.SetHardcodedApplicationName("storagenode")

allowDefaults := !isFilewalkerCommand()
Expand All @@ -25,7 +28,7 @@ func main() {
}

loggerFunc := func(logger *zap.Logger) *zap.Logger {
return logger.With(zap.String("process", rootCmd.Use))
return logger.With(zap.String("Process", rootCmd.Use))
}

process.ExecWithCustomOptions(rootCmd, process.ExecOptions{
Expand Down
3 changes: 3 additions & 0 deletions cmd/storj-admin/main.go
Expand Up @@ -75,5 +75,8 @@ func init() {
}

func main() {
logger, _, _ := process.NewLogger("storj-admin")
zap.ReplaceGlobals(logger)

process.Exec(rootCmd)
}
3 changes: 3 additions & 0 deletions cmd/tools/metabase-verify/main.go
Expand Up @@ -17,6 +17,9 @@ import (
var Error = errs.Class("metabase-verify")

func main() {
logger, _, _ := process.NewLogger("metabase-verify")
zap.ReplaceGlobals(logger)

log := zap.L()

root := &cobra.Command{
Expand Down
3 changes: 3 additions & 0 deletions cmd/tools/migrate-public-ids/main.go
Expand Up @@ -74,6 +74,9 @@ func run(cmd *cobra.Command, args []string) error {
}

func main() {
logger, _, _ := process.NewLogger("migrate-public-ids")
zap.ReplaceGlobals(logger)

process.Exec(rootCmd)
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/tools/node-cleanup/main.go
Expand Up @@ -83,6 +83,9 @@ func run(cmd *cobra.Command, args []string) error {
}

func main() {
logger, _, _ := process.NewLogger("node-cleanup")
zap.ReplaceGlobals(logger)

process.Exec(rootCmd)
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/tools/placement-test/main.go
Expand Up @@ -130,6 +130,9 @@ func init() {
}

func main() {
logger, _, _ := process.NewLogger("placement-test")
zap.ReplaceGlobals(logger)

process.ExecWithCustomOptions(rootCmd, process.ExecOptions{
LoadConfig: func(cmd *cobra.Command, vip *viper.Viper) error {
return nil
Expand Down
3 changes: 3 additions & 0 deletions cmd/tools/segment-verify/main.go
Expand Up @@ -310,6 +310,9 @@ func verifySegmentsCSV(ctx context.Context, service *Service, readCSVCfg ReadCSV
}

func main() {
logger, _, _ := process.NewLogger("segment-verify")
zap.ReplaceGlobals(logger)

process.Exec(rootCmd)
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/tools/tag-signer/main.go
Expand Up @@ -201,6 +201,9 @@ func parseTagPairs(tagPairs []string, allowCommaValues bool) ([]*pb.Tag, error)
}

func main() {
logger, _, _ := process.NewLogger("tag-signer")
zap.ReplaceGlobals(logger)

process.ExecWithCustomOptions(rootCmd, process.ExecOptions{
LoadConfig: func(cmd *cobra.Command, vip *viper.Viper) error {
return nil
Expand Down
3 changes: 3 additions & 0 deletions cmd/versioncontrol/main.go
Expand Up @@ -94,5 +94,8 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
}

func main() {
logger, _, _ := process.NewLogger("versioncontrol")
zap.ReplaceGlobals(logger)

process.Exec(rootCmd)
}

0 comments on commit 2108a62

Please sign in to comment.