mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-07-06 12:26:15 +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
|
package checkpoint
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
// Package cmdutils is the package that contains utilities for multus command
|
// Package cmdutils is the package that contains utilities for multus command
|
||||||
package cmdutils
|
package cmdutils
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
// Package cmdutils is the package that contains utilities for multus command
|
// Package cmdutils is the package that contains utilities for multus command
|
||||||
package cmdutils
|
package cmdutils
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
package k8sclient
|
package k8sclient
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
package kubeletclient
|
package kubeletclient
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -56,6 +56,11 @@ type LogOptions struct {
|
|||||||
|
|
||||||
// SetLogOptions set the LoggingOptions of NetConf
|
// SetLogOptions set the LoggingOptions of NetConf
|
||||||
func SetLogOptions(options *LogOptions) {
|
func SetLogOptions(options *LogOptions) {
|
||||||
|
// logger is used only if filname is supplied
|
||||||
|
if logger == nil || logger.Filename == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// give some default value
|
// give some default value
|
||||||
updatedLogger := lumberjack.Logger{
|
updatedLogger := lumberjack.Logger{
|
||||||
Filename: logger.Filename,
|
Filename: logger.Filename,
|
||||||
@ -176,16 +181,24 @@ func SetLogStderr(enable bool) {
|
|||||||
|
|
||||||
// SetLogFile sets logging file
|
// SetLogFile sets logging file
|
||||||
func SetLogFile(filename string) {
|
func SetLogFile(filename string) {
|
||||||
|
// logger is used only if filname is supplied
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedLogger := lumberjack.Logger{
|
updatedLogger := lumberjack.Logger{
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
MaxAge: logger.MaxAge,
|
MaxAge: 5,
|
||||||
MaxBackups: logger.MaxBackups,
|
MaxBackups: 5,
|
||||||
Compress: logger.Compress,
|
Compress: true,
|
||||||
MaxSize: logger.MaxSize,
|
MaxSize: 100,
|
||||||
LocalTime: logger.LocalTime,
|
}
|
||||||
|
|
||||||
|
if logger != nil {
|
||||||
|
updatedLogger.MaxAge = logger.MaxAge
|
||||||
|
updatedLogger.MaxBackups = logger.MaxBackups
|
||||||
|
updatedLogger.Compress = logger.Compress
|
||||||
|
updatedLogger.MaxSize = logger.MaxSize
|
||||||
}
|
}
|
||||||
logger = &updatedLogger
|
logger = &updatedLogger
|
||||||
loggingW = logger
|
loggingW = logger
|
||||||
@ -195,5 +208,5 @@ func init() {
|
|||||||
loggingStderr = true
|
loggingStderr = true
|
||||||
loggingW = nil
|
loggingW = nil
|
||||||
loggingLevel = PanicLevel
|
loggingLevel = PanicLevel
|
||||||
logger = &lumberjack.Logger{}
|
logger = nil
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
package logging
|
package logging
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -106,13 +108,13 @@ var _ = Describe("logging operations", func() {
|
|||||||
Verbosef("foobar")
|
Verbosef("foobar")
|
||||||
Expect(Errorf("foobar")).NotTo(BeNil())
|
Expect(Errorf("foobar")).NotTo(BeNil())
|
||||||
Panicf("foobar")
|
Panicf("foobar")
|
||||||
logger.Filename = ""
|
logger = nil
|
||||||
loggingW = nil
|
loggingW = nil
|
||||||
err = os.RemoveAll(tmpDir)
|
err = os.RemoveAll(tmpDir)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
// Revert the log variable to init
|
// Revert the log variable to init
|
||||||
loggingW = nil
|
loggingW = nil
|
||||||
logger = &lumberjack.Logger{}
|
logger = nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// Tests public getter
|
// Tests public getter
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package multus
|
package multus
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package multus
|
package multus
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package multus
|
package multus
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package multus
|
package multus
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
package netutils
|
package netutils
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
Loading…
Reference in New Issue
Block a user