Ignore errors when creating debug log file

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-05-25 14:44:00 +02:00
parent 5748d220ba
commit 61af2aee8e
2 changed files with 5 additions and 9 deletions

View File

@ -17,6 +17,7 @@
package runtime package runtime
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -43,7 +44,7 @@ func NewLogger() *Logger {
} }
// Update constructs a Logger with a preddefined formatter // Update constructs a Logger with a preddefined formatter
func (l *Logger) Update(filename string, logLevel string, argv []string) error { func (l *Logger) Update(filename string, logLevel string, argv []string) {
configFromArgs := parseArgs(argv) configFromArgs := parseArgs(argv)
@ -61,7 +62,7 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) error {
if !configFromArgs.version { if !configFromArgs.version {
configLogFile, err := createLogFile(filename) configLogFile, err := createLogFile(filename)
if err != nil { if err != nil {
return fmt.Errorf("error opening debug log file: %v", err) argLogFileError = errors.Join(argLogFileError, err)
} }
if configLogFile != nil { if configLogFile != nil {
logFiles = append(logFiles, configLogFile) logFiles = append(logFiles, configLogFile)
@ -71,7 +72,7 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) error {
if argLogFile != nil { if argLogFile != nil {
logFiles = append(logFiles, argLogFile) logFiles = append(logFiles, argLogFile)
} }
argLogFileError = err argLogFileError = errors.Join(argLogFileError, err)
} }
defer func() { defer func() {
if argLogFileError != nil { if argLogFileError != nil {
@ -119,8 +120,6 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) error {
previousLogger: l.Logger, previousLogger: l.Logger,
logFiles: logFiles, logFiles: logFiles,
} }
return nil
} }
// Reset closes the log file (if any) and resets the logger output to what it // Reset closes the log file (if any) and resets the logger output to what it

View File

@ -44,14 +44,11 @@ func (r rt) Run(argv []string) (rerr error) {
if err != nil { if err != nil {
return fmt.Errorf("error loading config: %v", err) return fmt.Errorf("error loading config: %v", err)
} }
err = r.logger.Update( r.logger.Update(
cfg.NVIDIAContainerRuntimeConfig.DebugFilePath, cfg.NVIDIAContainerRuntimeConfig.DebugFilePath,
cfg.NVIDIAContainerRuntimeConfig.LogLevel, cfg.NVIDIAContainerRuntimeConfig.LogLevel,
argv, argv,
) )
if err != nil {
return fmt.Errorf("failed to set up logger: %v", err)
}
defer func() { defer func() {
if rerr != nil { if rerr != nil {
r.logger.Errorf("%v", rerr) r.logger.Errorf("%v", rerr)