mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Use logger.Interface when resolving auto mode
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
c9b05d8fed
commit
9464953924
@ -14,6 +14,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||
)
|
||||
|
||||
@ -188,11 +189,11 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// logInterceptor implements the info.Logger interface to allow for logging from this function.
|
||||
type logInterceptor struct{}
|
||||
// logInterceptor implements the logger.Interface to allow for logging from executable.
|
||||
type logInterceptor struct {
|
||||
logger.NullLogger
|
||||
}
|
||||
|
||||
func (l *logInterceptor) Infof(format string, args ...interface{}) {
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
func (l *logInterceptor) Debugf(format string, args ...interface{}) {}
|
||||
|
@ -16,17 +16,13 @@
|
||||
|
||||
package info
|
||||
|
||||
import "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info"
|
||||
|
||||
// Logger is a basic interface for logging to allow these functions to be called
|
||||
// from code where logrus is not used.
|
||||
type Logger interface {
|
||||
Infof(string, ...interface{})
|
||||
Debugf(string, ...interface{})
|
||||
}
|
||||
import (
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info"
|
||||
)
|
||||
|
||||
// ResolveAutoMode determines the correct mode for the platform if set to "auto"
|
||||
func ResolveAutoMode(logger Logger, mode string) (rmode string) {
|
||||
func ResolveAutoMode(logger logger.Interface, mode string) (rmode string) {
|
||||
if mode != "auto" {
|
||||
return mode
|
||||
}
|
||||
|
@ -22,3 +22,29 @@ import "github.com/sirupsen/logrus"
|
||||
func New() Interface {
|
||||
return logrus.StandardLogger()
|
||||
}
|
||||
|
||||
// NullLogger is a logger that does nothing
|
||||
type NullLogger struct{}
|
||||
|
||||
var _ Interface = (*NullLogger)(nil)
|
||||
|
||||
// Debugf is a no-op for the null logger
|
||||
func (l *NullLogger) Debugf(string, ...interface{}) {}
|
||||
|
||||
// Errorf is a no-op for the null logger
|
||||
func (l *NullLogger) Errorf(string, ...interface{}) {}
|
||||
|
||||
// Info is a no-op for the null logger
|
||||
func (l *NullLogger) Info(...interface{}) {}
|
||||
|
||||
// Infof is a no-op for the null logger
|
||||
func (l *NullLogger) Infof(string, ...interface{}) {}
|
||||
|
||||
// Warn is a no-op for the null logger
|
||||
func (l *NullLogger) Warn(...interface{}) {}
|
||||
|
||||
// Warnf is a no-op for the null logger
|
||||
func (l *NullLogger) Warnf(string, ...interface{}) {}
|
||||
|
||||
// Warningf is a no-op for the null logger
|
||||
func (l *NullLogger) Warningf(string, ...interface{}) {}
|
||||
|
Loading…
Reference in New Issue
Block a user