mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-02-16 17:42:20 +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"
|
"syscall"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"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.
|
// logInterceptor implements the logger.Interface to allow for logging from executable.
|
||||||
type logInterceptor struct{}
|
type logInterceptor struct {
|
||||||
|
logger.NullLogger
|
||||||
|
}
|
||||||
|
|
||||||
func (l *logInterceptor) Infof(format string, args ...interface{}) {
|
func (l *logInterceptor) Infof(format string, args ...interface{}) {
|
||||||
log.Printf(format, args...)
|
log.Printf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logInterceptor) Debugf(format string, args ...interface{}) {}
|
|
||||||
|
@ -16,17 +16,13 @@
|
|||||||
|
|
||||||
package info
|
package info
|
||||||
|
|
||||||
import "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info"
|
import (
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
// Logger is a basic interface for logging to allow these functions to be called
|
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info"
|
||||||
// from code where logrus is not used.
|
)
|
||||||
type Logger interface {
|
|
||||||
Infof(string, ...interface{})
|
|
||||||
Debugf(string, ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveAutoMode determines the correct mode for the platform if set to "auto"
|
// 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" {
|
if mode != "auto" {
|
||||||
return mode
|
return mode
|
||||||
}
|
}
|
||||||
|
@ -22,3 +22,29 @@ import "github.com/sirupsen/logrus"
|
|||||||
func New() Interface {
|
func New() Interface {
|
||||||
return logrus.StandardLogger()
|
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