From caa998064e382e2d9dd58d6fe39d4db93d257111 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Thu, 21 Nov 2024 18:41:53 +0100 Subject: [PATCH] fixup: Respond to review feedback --- config/flags.go | 3 ++- tests/antithesis/avalanchego/gencomposeconfig/main.go | 3 +++ tests/antithesis/xsvm/gencomposeconfig/main.go | 3 +++ tests/e2e/etna/suites.go | 7 ++----- tests/fixture/bootstrapmonitor/cmd/main.go | 2 +- tests/fixture/tmpnet/cmd/main.go | 3 ++- tests/log.go | 2 +- utils/logging/format.go | 4 +++- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/config/flags.go b/config/flags.go index d8397ce40a2c..dbb5cd26cbdd 100644 --- a/config/flags.go +++ b/config/flags.go @@ -22,6 +22,7 @@ import ( "github.com/ava-labs/avalanchego/utils/compression" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/dynamicip" + "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/ulimit" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/gas" @@ -142,7 +143,7 @@ func addNodeFlags(fs *pflag.FlagSet) { fs.String(LogsDirKey, defaultLogDir, "Logging directory for Avalanche") fs.String(LogLevelKey, "info", "The log level. Should be one of {verbo, debug, trace, info, warn, error, fatal, off}") fs.String(LogDisplayLevelKey, "", "The log display level. If left blank, will inherit the value of log-level. Otherwise, should be one of {verbo, debug, trace, info, warn, error, fatal, off}") - fs.String(LogFormatKey, "auto", "The structure of log format. Defaults to 'auto' which formats terminal-like logs, when the output is a terminal. Otherwise, should be one of {auto, plain, colors, json}") + fs.String(LogFormatKey, logging.FormatModeAuto, fmt.Sprintf("The structure of log format. Defaults to '%s' which formats terminal-like logs, when the output is a terminal. Otherwise, should be one of {%s, plain, colors, json}", logging.FormatModeAuto, logging.FormatModeAuto)) fs.Uint(LogRotaterMaxSizeKey, 8, "The maximum file size in megabytes of the log file before it gets rotated.") fs.Uint(LogRotaterMaxFilesKey, 7, "The maximum number of old log files to retain. 0 means retain all old log files.") fs.Uint(LogRotaterMaxAgeKey, 0, "The maximum number of days to retain old log files based on the timestamp encoded in their filename. 0 means retain all old log files.") diff --git a/tests/antithesis/avalanchego/gencomposeconfig/main.go b/tests/antithesis/avalanchego/gencomposeconfig/main.go index 1681ad78e421..dcdd6e8c63c2 100644 --- a/tests/antithesis/avalanchego/gencomposeconfig/main.go +++ b/tests/antithesis/avalanchego/gencomposeconfig/main.go @@ -4,6 +4,8 @@ package main import ( + "os" + "go.uber.org/zap" "github.com/ava-labs/avalanchego/tests" @@ -20,5 +22,6 @@ func main() { tests.NewDefaultLogger("").Fatal("failed to generate compose config", zap.Error(err), ) + os.Exit(1) } } diff --git a/tests/antithesis/xsvm/gencomposeconfig/main.go b/tests/antithesis/xsvm/gencomposeconfig/main.go index 8bed3a982133..b292cf89cefb 100644 --- a/tests/antithesis/xsvm/gencomposeconfig/main.go +++ b/tests/antithesis/xsvm/gencomposeconfig/main.go @@ -4,6 +4,8 @@ package main import ( + "os" + "go.uber.org/zap" "github.com/ava-labs/avalanchego/genesis" @@ -25,5 +27,6 @@ func main() { tests.NewDefaultLogger("").Fatal("failed to generate compose config", zap.Error(err), ) + os.Exit(1) } } diff --git a/tests/e2e/etna/suites.go b/tests/e2e/etna/suites.go index 703249e0abdd..fb033726d6ce 100644 --- a/tests/e2e/etna/suites.go +++ b/tests/e2e/etna/suites.go @@ -29,13 +29,10 @@ var _ = ginkgo.Describe("[Etna]", func() { require.NoError(err) now := time.Now() - msg := "etna is activated" - if !upgrades.IsEtnaActivated(now) { - msg = "etna is not activated" - } - tc.Log().Info(msg, + tc.Log().Info("detected if Etna is activated", zap.Time("now", now), zap.Time("etnaTime", upgrades.EtnaTime), + zap.Bool("isEtnaActivated", upgrades.IsEtnaActivated(now)), ) }) }) diff --git a/tests/fixture/bootstrapmonitor/cmd/main.go b/tests/fixture/bootstrapmonitor/cmd/main.go index 1e04fd882ad6..af88d1d9eab7 100644 --- a/tests/fixture/bootstrapmonitor/cmd/main.go +++ b/tests/fixture/bootstrapmonitor/cmd/main.go @@ -40,7 +40,7 @@ func main() { rootCmd.PersistentFlags().StringVar(&podName, "pod-name", os.Getenv("POD_NAME"), "The name of the pod") rootCmd.PersistentFlags().StringVar(&nodeContainerName, "node-container-name", "", "The name of the node container in the pod") rootCmd.PersistentFlags().StringVar(&dataDir, "data-dir", "", "The path of the data directory used for the bootstrap job") - rootCmd.PersistentFlags().StringVar(&rawLogFormat, "log-format", "auto", "The structure of log format. Defaults to 'auto' which formats terminal-like logs, when the output is a terminal. Otherwise, should be one of {auto, plain, colors, json}") + rootCmd.PersistentFlags().StringVar(&rawLogFormat, "log-format", logging.FormatModeAuto, fmt.Sprintf("The structure of log format. Defaults to '%s' which formats terminal-like logs, when the output is a terminal. Otherwise, should be one of {%s, plain, colors, json}", logging.FormatModeAuto, logging.FormatModeAuto)) versionCmd := &cobra.Command{ Use: "version", diff --git a/tests/fixture/tmpnet/cmd/main.go b/tests/fixture/tmpnet/cmd/main.go index 96859fba4d8f..78b9f64f6d5f 100644 --- a/tests/fixture/tmpnet/cmd/main.go +++ b/tests/fixture/tmpnet/cmd/main.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanchego/tests" "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" + "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/version" ) @@ -37,7 +38,7 @@ func main() { Short: "tmpnetctl commands", } rootCmd.PersistentFlags().StringVar(&networkDir, "network-dir", os.Getenv(tmpnet.NetworkDirEnvName), "The path to the configuration directory of a temporary network") - rootCmd.PersistentFlags().StringVar(&rawLogFormat, "log-format", "auto", "The structure of log format. Defaults to 'auto' which formats terminal-like logs, when the output is a terminal. Otherwise, should be one of {auto, plain, colors, json}") + rootCmd.PersistentFlags().StringVar(&rawLogFormat, "log-format", logging.FormatModeAuto, fmt.Sprintf("The structure of log format. Defaults to '%s' which formats terminal-like logs, when the output is a terminal. Otherwise, should be one of {%s, plain, colors, json}", logging.FormatModeAuto, logging.FormatModeAuto)) versionCmd := &cobra.Command{ Use: "version", diff --git a/tests/log.go b/tests/log.go index 8e6271b8c014..8a6c4d7f4ca7 100644 --- a/tests/log.go +++ b/tests/log.go @@ -37,7 +37,7 @@ func NewSimpleLogger(writeCloser io.WriteCloser) logging.Logger { } func NewDefaultLogger(prefix string) logging.Logger { - log, err := LoggerForFormat(prefix, "auto") + log, err := LoggerForFormat(prefix, logging.FormatModeAuto) if err != nil { // This should never happen since auto is a valid log format panic(err) diff --git a/utils/logging/format.go b/utils/logging/format.go index 53313c3dad8f..7734fe49cf45 100644 --- a/utils/logging/format.go +++ b/utils/logging/format.go @@ -18,6 +18,8 @@ const ( Colors JSON + FormatModeAuto = "auto" + termTimeFormat = "[01-02|15:04:05.000]" ) @@ -58,7 +60,7 @@ func ToFormat(h string, fd uintptr) (Format, error) { return Colors, nil case "JSON": return JSON, nil - case "AUTO": + case strings.ToUpper(FormatModeAuto): if !term.IsTerminal(int(fd)) { return Plain, nil }