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

@@ -19,12 +19,12 @@ package cuda
import (
"path/filepath"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
"github.com/sirupsen/logrus"
)
type cudaLocator struct {
logger *logrus.Logger
logger logger.Interface
driverRoot string
}
@@ -32,7 +32,7 @@ type cudaLocator struct {
type Options func(*cudaLocator)
// WithLogger is an option that configures the logger used by the locator.
func WithLogger(logger *logrus.Logger) Options {
func WithLogger(logger logger.Interface) Options {
return func(c *cudaLocator) {
c.logger = logger
}
@@ -53,7 +53,7 @@ func New(opts ...Options) lookup.Locator {
}
if c.logger == nil {
c.logger = logrus.StandardLogger()
c.logger = logger.New()
}
if c.driverRoot == "" {
c.driverRoot = "/"

View File

@@ -20,12 +20,12 @@ import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
)
// NewDirectoryLocator creates a Locator that can be used to find directories at the specified root. A logger
// is also specified.
func NewDirectoryLocator(logger *log.Logger, root string) Locator {
func NewDirectoryLocator(logger logger.Interface, root string) Locator {
return NewFileLocator(
WithLogger(logger),
WithRoot(root),

View File

@@ -21,7 +21,7 @@ import (
"os"
"strings"
log "github.com/sirupsen/logrus"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
)
type executable struct {
@@ -29,13 +29,13 @@ type executable struct {
}
// NewExecutableLocator creates a locator to fine executable files in the path. A logger can also be specified.
func NewExecutableLocator(logger *log.Logger, root string) Locator {
func NewExecutableLocator(logger logger.Interface, root string) Locator {
paths := GetPaths(root)
return newExecutableLocator(logger, root, paths...)
}
func newExecutableLocator(logger *log.Logger, root string, paths ...string) *executable {
func newExecutableLocator(logger logger.Interface, root string, paths ...string) *executable {
f := newFileLocator(
WithLogger(logger),
WithRoot(root),

View File

@@ -21,13 +21,13 @@ import (
"os"
"path/filepath"
log "github.com/sirupsen/logrus"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
)
// file can be used to locate file (or file-like elements) at a specified set of
// prefixes. The validity of a file is determined by a filter function.
type file struct {
logger *log.Logger
logger logger.Interface
root string
prefixes []string
filter func(string) error
@@ -46,7 +46,7 @@ func WithRoot(root string) Option {
}
// WithLogger sets the logger for the file locator
func WithLogger(logger *log.Logger) Option {
func WithLogger(logger logger.Interface) Option {
return func(f *file) {
f.logger = logger
}
@@ -93,7 +93,7 @@ func newFileLocator(opts ...Option) *file {
opt(f)
}
if f.logger == nil {
f.logger = log.StandardLogger()
f.logger = logger.New()
}
if f.filter == nil {
f.filter = assertFile

View File

@@ -21,11 +21,11 @@ import (
"strings"
"github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache"
log "github.com/sirupsen/logrus"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
)
type library struct {
logger *log.Logger
logger logger.Interface
symlink Locator
cache ldcache.LDCache
}
@@ -33,7 +33,7 @@ type library struct {
var _ Locator = (*library)(nil)
// NewLibraryLocator creates a library locator using the specified logger.
func NewLibraryLocator(logger *log.Logger, root string) (Locator, error) {
func NewLibraryLocator(logger logger.Interface, root string) (Locator, error) {
cache, err := ldcache.New(logger, root)
if err != nil {
return nil, fmt.Errorf("error loading ldcache: %v", err)

View File

@@ -20,8 +20,8 @@ import (
"fmt"
"path/filepath"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
"github.com/sirupsen/logrus"
)
type symlinkChain struct {
@@ -34,7 +34,7 @@ type symlink struct {
// NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.
// A logger can also be specified.
func NewSymlinkChainLocator(logger *logrus.Logger, root string) Locator {
func NewSymlinkChainLocator(logger logger.Interface, root string) Locator {
f := newFileLocator(WithLogger(logger), WithRoot(root))
l := symlinkChain{
file: *f,
@@ -45,7 +45,7 @@ func NewSymlinkChainLocator(logger *logrus.Logger, root string) Locator {
// NewSymlinkLocator creats a locator that can be used for locating files through symlinks.
// A logger can also be specified.
func NewSymlinkLocator(logger *logrus.Logger, root string) Locator {
func NewSymlinkLocator(logger logger.Interface, root string) Locator {
f := newFileLocator(WithLogger(logger), WithRoot(root))
l := symlink{
file: *f,