From 39a1f3a04f6128f7420c5c07ae98015131d0ece3 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 14 Apr 2021 13:37:15 -0400 Subject: Recognize --log-level=trace "trace" is a valid logrus debugging level, so we should be able to tell the library to display messages logged at that level. Signed-off-by: Nalin Dahyabhai --- cmd/podman/common/completion.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index d110fb1b5..6086df297 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -21,7 +21,7 @@ var ( // ChangeCmds is the list of valid Change commands to passed to the Commit call ChangeCmds = []string{"CMD", "ENTRYPOINT", "ENV", "EXPOSE", "LABEL", "ONBUILD", "STOPSIGNAL", "USER", "VOLUME", "WORKDIR"} // LogLevels supported by podman - LogLevels = []string{"debug", "info", "warn", "warning", "error", "fatal", "panic"} + LogLevels = []string{"trace", "debug", "info", "warn", "warning", "error", "fatal", "panic"} ) type completeType int @@ -1009,7 +1009,7 @@ func AutocompleteEventBackend(cmd *cobra.Command, args []string, toComplete stri } // AutocompleteLogLevel - Autocomplete log level options. -// -> "debug", "info", "warn", "error", "fatal", "panic" +// -> "trace", "debug", "info", "warn", "error", "fatal", "panic" func AutocompleteLogLevel(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return LogLevels, cobra.ShellCompDirectiveNoFileComp } -- cgit v1.2.3-54-g00ecf From 9b3226a80a35ee85eebb6d910f9608dc301f0e72 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 14 Apr 2021 13:38:27 -0400 Subject: pkg/errorhandling.JoinErrors: don't throw away context for lone errors When our multierror contains just one error, don't extract its text only to rewrap it, because doing so discards any stack trace information that might have been added closer to where the error actually originated. Signed-off-by: Nalin Dahyabhai --- pkg/errorhandling/errorhandling.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/errorhandling/errorhandling.go b/pkg/errorhandling/errorhandling.go index b1923be98..9dc545ebb 100644 --- a/pkg/errorhandling/errorhandling.go +++ b/pkg/errorhandling/errorhandling.go @@ -24,6 +24,9 @@ func JoinErrors(errs []error) error { if finalErr == nil { return finalErr } + if len(multiE.WrappedErrors()) == 1 && logrus.IsLevelEnabled(logrus.TraceLevel) { + return multiE.WrappedErrors()[0] + } return errors.New(strings.TrimSpace(finalErr.Error())) } -- cgit v1.2.3-54-g00ecf From 6bde4d00dd5d1ce62585c3aac10076d53b3d9e1f Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 14 Apr 2021 13:43:58 -0400 Subject: At trace log level, print error text using %+v instead of %v If we're logging at trace level, use %+v instead of %v when printing an error at exit. If the error included stack information, this will cause the backtrace to be printed, which is very handy for debugging. Signed-off-by: Nalin Dahyabhai --- cmd/podman/root.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 4527c2646..9e5d2a236 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -416,7 +416,11 @@ func formatError(err error) string { strings.TrimSuffix(err.Error(), ": "+define.ErrOCIRuntime.Error()), ) } else { - message = "Error: " + err.Error() + if logrus.IsLevelEnabled(logrus.TraceLevel) { + message = fmt.Sprintf("Error: %+v", err) + } else { + message = fmt.Sprintf("Error: %v", err) + } } return message } -- cgit v1.2.3-54-g00ecf From bc86c50cd81bc3267ec8b9840e1a0e705231f336 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 14 Apr 2021 14:15:13 -0400 Subject: Test that we don't error out on advertised --log-level values Signed-off-by: Nalin Dahyabhai --- test/system/001-basic.bats | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats index 081bb1171..35107f0a0 100644 --- a/test/system/001-basic.bats +++ b/test/system/001-basic.bats @@ -111,4 +111,17 @@ function setup() { is "$output" "you found me" "sample invocation of 'jq'" } +@test "podman --log-level recognizes log levels" { + run_podman 1 --log-level=telepathic info + is "$output" 'Log Level "telepathic" is not supported.*' + run_podman --log-level=trace info + run_podman --log-level=debug info + run_podman --log-level=info info + run_podman --log-level=warn info + run_podman --log-level=warning info + run_podman --log-level=error info + run_podman --log-level=fatal info + run_podman --log-level=panic info +} + # vim: filetype=sh -- cgit v1.2.3-54-g00ecf