Define a basic logger interface

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2023-03-22 14:27:43 +02:00
parent 6a04e97bca
commit a02bc27c3e
78 changed files with 307 additions and 246 deletions

View File

@@ -16,13 +16,13 @@
package system
import "github.com/sirupsen/logrus"
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
// Option is a functional option for the system command
type Option func(*Interface)
// WithLogger sets the logger for the system command
func WithLogger(logger *logrus.Logger) Option {
func WithLogger(logger logger.Interface) Option {
return func(i *Interface) {
i.logger = logger
}

View File

@@ -24,13 +24,13 @@ import (
"strings"
"github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc/devices"
"github.com/sirupsen/logrus"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"golang.org/x/sys/unix"
)
// Interface is the interface for the system command
type Interface struct {
logger *logrus.Logger
logger logger.Interface
dryRun bool
loadKernelModules bool
nvidiaDevices nvidiaDevices
@@ -39,7 +39,7 @@ type Interface struct {
// New constructs a system command with the specified options
func New(opts ...Option) (*Interface, error) {
i := &Interface{
logger: logrus.StandardLogger(),
logger: logger.New(),
}
for _, opt := range opts {
opt(i)