Provide the option to not to log via STDERR

Today, Multus will always log via STDERR, and these logs will then
logged by the Kubelet. If we also choose to have Multus log to a file by
setting the LogFile option in the CNI configuration, the same logs will
be logged twice.

This commit provide the option to disable logging to STDERR.

Signed-off-by: Yun Zhou <yunz@nvidia.com>
This commit is contained in:
Yun Zhou
2021-02-23 15:01:58 -08:00
committed by Tomofumi Hayashi
parent 5141eab28a
commit dc9315f125
4 changed files with 26 additions and 2 deletions

View File

@@ -257,7 +257,8 @@ func GetGatewayFromResult(result *current.Result) []net.IP {
// LoadNetConf converts inputs (i.e. stdin) to NetConf
func LoadNetConf(bytes []byte) (*NetConf, error) {
netconf := &NetConf{}
// LogToStderr's default value set to true
netconf := &NetConf{LogToStderr: true}
logging.Debugf("LoadNetConf: %s", string(bytes))
if err := json.Unmarshal(bytes, netconf); err != nil {
@@ -265,6 +266,7 @@ func LoadNetConf(bytes []byte) (*NetConf, error) {
}
// Logging
logging.SetLogStderr(netconf.LogToStderr)
if netconf.LogFile != "" {
logging.SetLogFile(netconf.LogFile)
}

View File

@@ -43,6 +43,7 @@ type NetConf struct {
DefaultNetworks []string `json:"defaultNetworks"`
LogFile string `json:"logFile"`
LogLevel string `json:"logLevel"`
LogToStderr bool `json:"logToStderr,omitempty"`
RuntimeConfig *RuntimeConfig `json:"runtimeConfig,omitempty"`
// Default network readiness options
ReadinessIndicatorFile string `json:"readinessindicatorfile"`