Merge pull request #10032 from nalind/trace-level

Recognize "trace" logging, and use it for lone errors at exit
This commit is contained in:
OpenShift Merge Robot
2021-04-15 09:08:37 -04:00
committed by GitHub
4 changed files with 23 additions and 3 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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()))
}

View File

@ -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