mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-07-05 20:06:16 +00:00
Merge pull request #1194 from s1061123/fix-logging
Fix to use lumberjack only for logging files
This commit is contained in:
commit
c76db9c7a0
@ -15,6 +15,8 @@
|
||||
|
||||
package checkpoint
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
package k8sclient
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
package kubeletclient
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
package multus
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
package multus
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
package multus
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
package multus
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
package netutils
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
package server
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
package server
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
package types
|
||||
|
||||
// disable dot-imports only for testing
|
||||
//revive:disable:dot-imports
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
Loading…
Reference in New Issue
Block a user