From 0e52de5a4bc4d0c267bcfd009cbd7385a301eceb Mon Sep 17 00:00:00 2001 From: John-Alan Simmons Date: Fri, 29 Jul 2022 16:53:18 -0400 Subject: [PATCH 1/4] fixed logger not correctly applying --- cli/root.go | 8 ++++---- config/config.go | 5 ----- tests/integration/cli/log_config_test.go | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cli/root.go b/cli/root.go index e4c34b26e3..3d93f35175 100644 --- a/cli/root.go +++ b/cli/root.go @@ -80,7 +80,7 @@ func init() { "loglevel", cfg.Log.Level, "Log level to use. Options are debug, info, error, fatal", ) - err := viper.BindPFlag("logging.level", rootCmd.PersistentFlags().Lookup("loglevel")) + err := viper.BindPFlag("log.level", rootCmd.PersistentFlags().Lookup("loglevel")) if err != nil { log.FatalE(context.Background(), "Could not bind logging.loglevel", err) } @@ -94,7 +94,7 @@ func init() { "logoutput", cfg.Log.OutputPath, "Log output path", ) - err = viper.BindPFlag("logging.outputpath", rootCmd.PersistentFlags().Lookup("logoutput")) + err = viper.BindPFlag("log.outputpath", rootCmd.PersistentFlags().Lookup("logoutput")) if err != nil { log.FatalE(context.Background(), "Could not bind log.outputpath", err) } @@ -103,7 +103,7 @@ func init() { "logformat", cfg.Log.Format, "Log format to use. Options are csv, json", ) - err = viper.BindPFlag("logging.format", rootCmd.PersistentFlags().Lookup("logformat")) + err = viper.BindPFlag("log.format", rootCmd.PersistentFlags().Lookup("logformat")) if err != nil { log.FatalE(context.Background(), "Could not bind log.format", err) } @@ -112,7 +112,7 @@ func init() { "logtrace", cfg.Log.Stacktrace, "Include stacktrace in error and fatal logs", ) - err = viper.BindPFlag("logging.stacktrace", rootCmd.PersistentFlags().Lookup("logtrace")) + err = viper.BindPFlag("log.stacktrace", rootCmd.PersistentFlags().Lookup("logtrace")) if err != nil { log.FatalE(context.Background(), "Could not bind log.stacktrace", err) } diff --git a/config/config.go b/config/config.go index 611a9a9a10..63f7eef46e 100644 --- a/config/config.go +++ b/config/config.go @@ -362,11 +362,6 @@ func defaultLogConfig() *LoggingConfig { } func (logcfg *LoggingConfig) validate() error { - switch logcfg.Level { - case logLevelDebug, logLevelInfo, logLevelError, logLevelFatal: - default: - return fmt.Errorf("invalid log level: %s", logcfg.Level) - } return nil } diff --git a/tests/integration/cli/log_config_test.go b/tests/integration/cli/log_config_test.go index 62d955ab89..4d5f41127e 100644 --- a/tests/integration/cli/log_config_test.go +++ b/tests/integration/cli/log_config_test.go @@ -52,7 +52,7 @@ func TestCLILogsToStderrGivenNamedLogLevel(t *testing.T) { log1.Error(ctx, "error") log1.Debug(ctx, "debug") log2.Info(ctx, "info") - log3.Debug(ctx, "info") + log3.Debug(ctx, "info") // wont print, as logger3 will use global level defined above as 'error' }, ) From fba7e2fd5a3e10ee4698c30c9a82bbf77e2be501 Mon Sep 17 00:00:00 2001 From: John-Alan Simmons Date: Fri, 29 Jul 2022 16:58:19 -0400 Subject: [PATCH 2/4] added test line --- tests/integration/cli/log_config_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/cli/log_config_test.go b/tests/integration/cli/log_config_test.go index 4d5f41127e..2acd1477d8 100644 --- a/tests/integration/cli/log_config_test.go +++ b/tests/integration/cli/log_config_test.go @@ -52,7 +52,8 @@ func TestCLILogsToStderrGivenNamedLogLevel(t *testing.T) { log1.Error(ctx, "error") log1.Debug(ctx, "debug") log2.Info(ctx, "info") - log3.Debug(ctx, "info") // wont print, as logger3 will use global level defined above as 'error' + log3.Debug(ctx, "debug") // wont print, as logger3 will use global level defined above as 'error' + log3.Info(ctx, "info") // wont print, as logger3 will use global level defined above as 'error' }, ) From b5b4aa0fd427853cfdacfbeb7efc56138f0ccea7 Mon Sep 17 00:00:00 2001 From: John-Alan Simmons Date: Fri, 29 Jul 2022 17:01:08 -0400 Subject: [PATCH 3/4] Added caller to exported config.Logger call --- config/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config.go b/config/config.go index 63f7eef46e..3909a38fb5 100644 --- a/config/config.go +++ b/config/config.go @@ -403,6 +403,7 @@ func (logcfg LoggingConfig) ToLoggerConfig() (logging.Config, error) { DisableColor: logging.NewDisableColorOption(logcfg.NoColor), EncoderFormat: logging.NewEncoderFormatOption(encfmt), OutputPaths: []string{logcfg.OutputPath}, + EnableCaller: logging.NewEnableCallerOption(logcfg.Caller), OverridesByLoggerName: overrides, }, nil } From 27aa302bf31328b3fcfe4c5ab11f8742ef0cec70 Mon Sep 17 00:00:00 2001 From: John-Alan Simmons Date: Sat, 30 Jul 2022 04:35:53 -0400 Subject: [PATCH 4/4] Add caller option to --logger override --- cli/cli.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/cli.go b/cli/cli.go index 50c5df932c..f90eee81f1 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -162,6 +162,12 @@ func parseAndConfigLogAllParams(ctx context.Context, cfg *config.LoggingConfig, return fmt.Errorf("couldn't parse kv bool: %w", err) } logcfg.NoColor = boolValue + case "caller": // bool + boolValue, err := strconv.ParseBool(parsedKV[1]) + if err != nil { + return fmt.Errorf("couldn't parse kv bool: %w", err) + } + logcfg.Caller = boolValue default: return fmt.Errorf("unknown parameter for logger: %s", param) }