diff --git a/pkg/checkpoint/checkpoint_test.go b/pkg/checkpoint/checkpoint_test.go index ef5edd7b9..42f89cae7 100644 --- a/pkg/checkpoint/checkpoint_test.go +++ b/pkg/checkpoint/checkpoint_test.go @@ -15,6 +15,8 @@ package checkpoint +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "fmt" "os" diff --git a/pkg/cmdutils/cmdutils_suite_test.go b/pkg/cmdutils/cmdutils_suite_test.go index e936a7063..89c1768b0 100644 --- a/pkg/cmdutils/cmdutils_suite_test.go +++ b/pkg/cmdutils/cmdutils_suite_test.go @@ -15,6 +15,8 @@ // Package cmdutils is the package that contains utilities for multus command package cmdutils +// disable dot-imports only for testing +//revive:disable:dot-imports import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/pkg/cmdutils/utils_test.go b/pkg/cmdutils/utils_test.go index e7fdef767..7c6392782 100644 --- a/pkg/cmdutils/utils_test.go +++ b/pkg/cmdutils/utils_test.go @@ -15,6 +15,8 @@ // Package cmdutils is the package that contains utilities for multus command package cmdutils +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "fmt" "os" diff --git a/pkg/k8sclient/k8sclient_test.go b/pkg/k8sclient/k8sclient_test.go index b1ab352ed..a4b379aec 100644 --- a/pkg/k8sclient/k8sclient_test.go +++ b/pkg/k8sclient/k8sclient_test.go @@ -15,6 +15,8 @@ package k8sclient +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "fmt" "os" diff --git a/pkg/kubeletclient/kubeletclient_test.go b/pkg/kubeletclient/kubeletclient_test.go index 2b1049750..668055176 100644 --- a/pkg/kubeletclient/kubeletclient_test.go +++ b/pkg/kubeletclient/kubeletclient_test.go @@ -15,6 +15,8 @@ package kubeletclient +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "context" "fmt" diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go index f621807f7..5996a07af 100644 --- a/pkg/logging/logging.go +++ b/pkg/logging/logging.go @@ -56,6 +56,11 @@ type LogOptions struct { // SetLogOptions set the LoggingOptions of NetConf func SetLogOptions(options *LogOptions) { + // logger is used only if filname is supplied + if logger == nil || logger.Filename == "" { + return + } + // give some default value updatedLogger := lumberjack.Logger{ Filename: logger.Filename, @@ -176,16 +181,24 @@ func SetLogStderr(enable bool) { // SetLogFile sets logging file func SetLogFile(filename string) { + // logger is used only if filname is supplied if filename == "" { return } + updatedLogger := lumberjack.Logger{ Filename: filename, - MaxAge: logger.MaxAge, - MaxBackups: logger.MaxBackups, - Compress: logger.Compress, - MaxSize: logger.MaxSize, - LocalTime: logger.LocalTime, + MaxAge: 5, + MaxBackups: 5, + Compress: true, + MaxSize: 100, + } + + if logger != nil { + updatedLogger.MaxAge = logger.MaxAge + updatedLogger.MaxBackups = logger.MaxBackups + updatedLogger.Compress = logger.Compress + updatedLogger.MaxSize = logger.MaxSize } logger = &updatedLogger loggingW = logger @@ -195,5 +208,5 @@ func init() { loggingStderr = true loggingW = nil loggingLevel = PanicLevel - logger = &lumberjack.Logger{} + logger = nil } diff --git a/pkg/logging/logging_test.go b/pkg/logging/logging_test.go index c33007e6f..234d59d0d 100644 --- a/pkg/logging/logging_test.go +++ b/pkg/logging/logging_test.go @@ -15,6 +15,8 @@ package logging +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "fmt" "os" @@ -106,13 +108,13 @@ var _ = Describe("logging operations", func() { Verbosef("foobar") Expect(Errorf("foobar")).NotTo(BeNil()) Panicf("foobar") - logger.Filename = "" + logger = nil loggingW = nil err = os.RemoveAll(tmpDir) Expect(err).NotTo(HaveOccurred()) // Revert the log variable to init loggingW = nil - logger = &lumberjack.Logger{} + logger = nil }) // Tests public getter diff --git a/pkg/multus/multus_cni020_test.go b/pkg/multus/multus_cni020_test.go index 2d53ec1c7..6340506c9 100644 --- a/pkg/multus/multus_cni020_test.go +++ b/pkg/multus/multus_cni020_test.go @@ -14,6 +14,8 @@ package multus +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "context" "fmt" diff --git a/pkg/multus/multus_cni040_test.go b/pkg/multus/multus_cni040_test.go index 3e9f8f397..9fb54739e 100644 --- a/pkg/multus/multus_cni040_test.go +++ b/pkg/multus/multus_cni040_test.go @@ -14,6 +14,8 @@ package multus +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "context" "fmt" diff --git a/pkg/multus/multus_cni100_test.go b/pkg/multus/multus_cni100_test.go index 51c4b6e23..e1ee52645 100644 --- a/pkg/multus/multus_cni100_test.go +++ b/pkg/multus/multus_cni100_test.go @@ -14,6 +14,8 @@ package multus +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "context" "fmt" diff --git a/pkg/multus/multus_suite_test.go b/pkg/multus/multus_suite_test.go index e635d1c36..f92b6e7da 100644 --- a/pkg/multus/multus_suite_test.go +++ b/pkg/multus/multus_suite_test.go @@ -14,6 +14,8 @@ package multus +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "bytes" "context" diff --git a/pkg/netutils/netutils_test.go b/pkg/netutils/netutils_test.go index d907184e1..14e26029a 100644 --- a/pkg/netutils/netutils_test.go +++ b/pkg/netutils/netutils_test.go @@ -15,6 +15,8 @@ package netutils +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "encoding/json" "net" diff --git a/pkg/server/exec_chroot_test.go b/pkg/server/exec_chroot_test.go index 3290355b1..5b8f0fdad 100644 --- a/pkg/server/exec_chroot_test.go +++ b/pkg/server/exec_chroot_test.go @@ -14,6 +14,8 @@ package server +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "context" "os" diff --git a/pkg/server/server_suite_test.go b/pkg/server/server_suite_test.go index bc80c1428..042e88cb3 100644 --- a/pkg/server/server_suite_test.go +++ b/pkg/server/server_suite_test.go @@ -14,6 +14,8 @@ package server +// disable dot-imports only for testing +//revive:disable:dot-imports import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 597fdb382..047ad632c 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -14,6 +14,8 @@ package server +// disable dot-imports only for testing +//revive:disable:dot-imports import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/pkg/server/thick_cni_test.go b/pkg/server/thick_cni_test.go index 917c3e6ea..3661c9f27 100644 --- a/pkg/server/thick_cni_test.go +++ b/pkg/server/thick_cni_test.go @@ -14,6 +14,8 @@ package server +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "context" "fmt" diff --git a/pkg/types/conf_test.go b/pkg/types/conf_test.go index a2dc647f8..5bb8d4425 100644 --- a/pkg/types/conf_test.go +++ b/pkg/types/conf_test.go @@ -15,6 +15,8 @@ package types +// disable dot-imports only for testing +//revive:disable:dot-imports import ( "encoding/json" "fmt"