From 723d18c5d4e21660a14a97d2e0e7418ec8bbe837 Mon Sep 17 00:00:00 2001 From: Murcherla Date: Fri, 14 Aug 2020 09:52:10 -0500 Subject: [PATCH] fix logging --- cmd/aws-k8s-agent/main.go | 5 ++--- cmd/cni-metrics-helper/main.go | 3 --- cmd/routed-eni-cni-plugin/cni.go | 1 - cmd/routed-eni-cni-plugin/driver/driver_test.go | 1 - pkg/ipamd/datastore/data_store_test.go | 1 - pkg/utils/logger/config.go | 7 ++----- pkg/utils/logger/logger.go | 7 ------- pkg/utils/logger/logger_test.go | 4 ++-- pkg/utils/logger/zaplogger.go | 2 +- 9 files changed, 7 insertions(+), 24 deletions(-) diff --git a/cmd/aws-k8s-agent/main.go b/cmd/aws-k8s-agent/main.go index c958816fdb..6f43b8082d 100644 --- a/cmd/aws-k8s-agent/main.go +++ b/cmd/aws-k8s-agent/main.go @@ -22,8 +22,6 @@ import ( "github.com/aws/amazon-vpc-cni-k8s/pkg/utils/logger" ) -const binaryName = "ipamd" - var version string func main() { @@ -33,7 +31,8 @@ func main() { func _main() int { //Do not add anything before initializing logger logConfig := logger.Configuration{ - BinaryName: binaryName, + LogLevel: logger.GetLogLevel(), + LogLocation: logger.GetLogLocation(), } log := logger.New(&logConfig) diff --git a/cmd/cni-metrics-helper/main.go b/cmd/cni-metrics-helper/main.go index fcfdf94008..9939aa8f0a 100644 --- a/cmd/cni-metrics-helper/main.go +++ b/cmd/cni-metrics-helper/main.go @@ -29,8 +29,6 @@ import ( "github.com/aws/amazon-vpc-cni-k8s/pkg/publisher" ) -const binaryName = "cni-metrics-helper" - type options struct { submitCW bool help bool @@ -40,7 +38,6 @@ func main() { // Do not add anything before initializing logger logLevel := logger.GetLogLevel() logConfig := logger.Configuration{ - BinaryName: binaryName, LogLevel: logLevel, LogLocation: "stdout", } diff --git a/cmd/routed-eni-cni-plugin/cni.go b/cmd/routed-eni-cni-plugin/cni.go index 5e1808317b..c81f7dcd01 100644 --- a/cmd/routed-eni-cni-plugin/cni.go +++ b/cmd/routed-eni-cni-plugin/cni.go @@ -91,7 +91,6 @@ func LoadNetConf(bytes []byte) (*NetConf, logger.Logger, error) { //logConfig logConfig := logger.Configuration{ - BinaryName: conf.Name, LogLevel: conf.PluginLogLevel, LogLocation: conf.PluginLogFile, } diff --git a/cmd/routed-eni-cni-plugin/driver/driver_test.go b/cmd/routed-eni-cni-plugin/driver/driver_test.go index 2423f55fa3..b8c1a99fa0 100644 --- a/cmd/routed-eni-cni-plugin/driver/driver_test.go +++ b/cmd/routed-eni-cni-plugin/driver/driver_test.go @@ -49,7 +49,6 @@ const ( ) var logConfig = logger.Configuration{ - BinaryName: "aws-cni", LogLevel: "Debug", LogLocation: "stdout", } diff --git a/pkg/ipamd/datastore/data_store_test.go b/pkg/ipamd/datastore/data_store_test.go index 6a37edf348..6496e485d6 100644 --- a/pkg/ipamd/datastore/data_store_test.go +++ b/pkg/ipamd/datastore/data_store_test.go @@ -24,7 +24,6 @@ import ( ) var logConfig = logger.Configuration{ - BinaryName: "aws-cni", LogLevel: "Debug", LogLocation: "stdout", } diff --git a/pkg/utils/logger/config.go b/pkg/utils/logger/config.go index 469d2cd364..c594648daf 100644 --- a/pkg/utils/logger/config.go +++ b/pkg/utils/logger/config.go @@ -20,28 +20,25 @@ import ( const ( defaultLogFilePath = "/host/var/log/aws-routed-eni/ipamd.log" defaultLogLevel = "Debug" - binaryName = "L-IPamD" envLogLevel = "AWS_VPC_K8S_CNI_LOGLEVEL" envLogFilePath = "AWS_VPC_K8S_CNI_LOG_FILE" ) // Configuration stores the config for the logger type Configuration struct { - BinaryName string LogLevel string LogLocation string } func LoadLogConfig() *Configuration { return &Configuration{ - BinaryName: binaryName, LogLevel: GetLogLevel(), - LogLocation: getLogFileLocation(), + LogLocation: GetLogLocation(), } } // GetLogFileLocation returns the log file path -func getLogFileLocation() string { +func GetLogLocation() string { logFilePath := os.Getenv(envLogFilePath) if logFilePath == "" { logFilePath = defaultLogFilePath diff --git a/pkg/utils/logger/logger.go b/pkg/utils/logger/logger.go index 22dbc452f9..5b232114d0 100644 --- a/pkg/utils/logger/logger.go +++ b/pkg/utils/logger/logger.go @@ -13,8 +13,6 @@ package logger -const ipamdBinaryName = "aws-k8s-agent" - //Log is global variable so that log functions can be directly accessed var log Logger @@ -64,11 +62,6 @@ func (logf *structuredLogger) isEmpty() bool { //New logger initializes logger func New(inputLogConfig *Configuration) Logger { - if inputLogConfig.BinaryName == ipamdBinaryName { - logConfig := LoadLogConfig() - log = logConfig.newZapLogger() - return log - } log = inputLogConfig.newZapLogger() return log } diff --git a/pkg/utils/logger/logger_test.go b/pkg/utils/logger/logger_test.go index a7abdfedca..d488f9932d 100644 --- a/pkg/utils/logger/logger_test.go +++ b/pkg/utils/logger/logger_test.go @@ -26,12 +26,12 @@ func TestEnvLogFilePath(t *testing.T) { _ = os.Setenv(envLogFilePath, path) defer os.Unsetenv(envLogFilePath) - assert.Equal(t, path, getLogFileLocation()) + assert.Equal(t, path, GetLogLocation()) } func TestGetLogFileLocationReturnsDefaultPath(t *testing.T) { defaultPath := "/host/var/log/aws-routed-eni/ipamd.log" - assert.Equal(t, defaultPath, getLogFileLocation()) + assert.Equal(t, defaultPath, GetLogLocation()) } func TestLogLevelReturnsOverriddenLevel(t *testing.T) { diff --git a/pkg/utils/logger/zaplogger.go b/pkg/utils/logger/zaplogger.go index 981b3dd292..306736b3fd 100644 --- a/pkg/utils/logger/zaplogger.go +++ b/pkg/utils/logger/zaplogger.go @@ -20,7 +20,7 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" - lumberjack "gopkg.in/natefinch/lumberjack.v2" + "gopkg.in/natefinch/lumberjack.v2" ) type structuredLogger struct {