Fix logging to stderr instead of file logger

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2021-11-16 21:37:50 +01:00
parent d2575abd3a
commit 58801d0c71

View File

@ -32,7 +32,7 @@ func NewLowLevelRuntime(candidates ...string) (Runtime, error) {
// NewLowLevelRuntimeWithLogger creates a Runtime as with NewLowLevelRuntime using the specified logger. // NewLowLevelRuntimeWithLogger creates a Runtime as with NewLowLevelRuntime using the specified logger.
func NewLowLevelRuntimeWithLogger(logger *log.Logger, candidates ...string) (Runtime, error) { func NewLowLevelRuntimeWithLogger(logger *log.Logger, candidates ...string) (Runtime, error) {
runtimePath, err := findRuntime(candidates) runtimePath, err := findRuntime(logger, candidates)
if err != nil { if err != nil {
return nil, fmt.Errorf("error locating runtime: %v", err) return nil, fmt.Errorf("error locating runtime: %v", err)
} }
@ -42,19 +42,19 @@ func NewLowLevelRuntimeWithLogger(logger *log.Logger, candidates ...string) (Run
// findRuntime checks elements in a list of supplied candidates for a matching executable in the PATH. // findRuntime checks elements in a list of supplied candidates for a matching executable in the PATH.
// The absolute path to the first match is returned. // The absolute path to the first match is returned.
func findRuntime(candidates []string) (string, error) { func findRuntime(logger *log.Logger, candidates []string) (string, error) {
if len(candidates) == 0 { if len(candidates) == 0 {
return "", fmt.Errorf("at least one runtime candidate must be specified") return "", fmt.Errorf("at least one runtime candidate must be specified")
} }
for _, candidate := range candidates { for _, candidate := range candidates {
log.Infof("Looking for runtime binary '%v'", candidate) logger.Infof("Looking for runtime binary '%v'", candidate)
runcPath, err := exec.LookPath(candidate) runcPath, err := exec.LookPath(candidate)
if err == nil { if err == nil {
log.Infof("Found runtime binary '%v'", runcPath) logger.Infof("Found runtime binary '%v'", runcPath)
return runcPath, nil return runcPath, nil
} }
log.Warnf("Runtime binary '%v' not found: %v", candidate, err) logger.Warnf("Runtime binary '%v' not found: %v", candidate, err)
} }
return "", fmt.Errorf("no runtime binary found from candidate list: %v", candidates) return "", fmt.Errorf("no runtime binary found from candidate list: %v", candidates)