Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to use lumberjack only for logging files #1194

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/checkpoint/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package checkpoint

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"fmt"
"os"
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmdutils/cmdutils_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmdutils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions pkg/k8sclient/k8sclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package k8sclient

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"fmt"
"os"
Expand Down
2 changes: 2 additions & 0 deletions pkg/kubeletclient/kubeletclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package kubeletclient

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"context"
"fmt"
Expand Down
25 changes: 19 additions & 6 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -195,5 +208,5 @@ func init() {
loggingStderr = true
loggingW = nil
loggingLevel = PanicLevel
logger = &lumberjack.Logger{}
logger = nil
}
6 changes: 4 additions & 2 deletions pkg/logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package logging

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"fmt"
"os"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/multus/multus_cni020_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package multus

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"context"
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions pkg/multus/multus_cni040_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package multus

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"context"
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions pkg/multus/multus_cni100_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package multus

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"context"
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions pkg/multus/multus_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package multus

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"bytes"
"context"
Expand Down
2 changes: 2 additions & 0 deletions pkg/netutils/netutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package netutils

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"encoding/json"
"net"
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/exec_chroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package server

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"context"
"os"
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/server_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/thick_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package server

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"context"
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package types

// disable dot-imports only for testing
//revive:disable:dot-imports
import (
"encoding/json"
"fmt"
Expand Down
Loading