diff --git a/common/common.go b/common/common.go index 3f6cf3e909..5d3bb99b62 100644 --- a/common/common.go +++ b/common/common.go @@ -27,8 +27,8 @@ import ( const ( // EnvVarKubeConfig is the path to the Kubernetes configuration EnvVarKubeConfig = "KUBECONFIG" - // EnvVarDebugLog is the env var to turn on the debug mode for logging - EnvVarDebugLog = "DEBUG_LOG" + // EnvVarLogLog is the env var to select the log level - options are debug, info, error + EnvVarLogLevel = "LOG_LEVEL" // ENVVarPodName should be set to the name of the pod EnvVarPodName = "POD_NAME" // ENVVarLeaderElection sets the leader election mode diff --git a/common/logging/logger.go b/common/logging/logger.go index 9a059f3bd8..bd30f27396 100644 --- a/common/logging/logger.go +++ b/common/logging/logger.go @@ -41,17 +41,15 @@ const ( LabelHTTPMethod = "http-method" LabelTime = "time" TimestampFormat = "2006-01-02 15:04:05" + InfoLevel = "info" + DebugLevel = "debug" + ErrorLevel = "error" ) // NewArgoEventsLogger returns a new ArgoEventsLogger func NewArgoEventsLogger() *zap.SugaredLogger { - var config zap.Config - debugMode, ok := os.LookupEnv(common.EnvVarDebugLog) - if ok && debugMode == "true" { - config = zap.NewDevelopmentConfig() - } else { - config = zap.NewProductionConfig() - } + logLevel, _ := os.LookupEnv(common.EnvVarLogLevel) + config := ConfigureLogLevelLogger(logLevel) // Config customization goes here if any config.OutputPaths = []string{"stdout"} logger, err := config.Build() @@ -81,3 +79,19 @@ func FromContext(ctx context.Context) *zap.SugaredLogger { } return NewArgoEventsLogger() } + +// Returns logger conifg depending on the log level +func ConfigureLogLevelLogger(logLevel string) zap.Config { + logConfig := zap.NewProductionConfig() + switch logLevel { + case InfoLevel: + logConfig.Level = zap.NewAtomicLevelAt(zap.InfoLevel) + case ErrorLevel: + logConfig.Level = zap.NewAtomicLevelAt(zap.ErrorLevel) + case DebugLevel: + logConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel) + default: + logConfig.Level = zap.NewAtomicLevelAt(zap.InfoLevel) + } + return logConfig +} diff --git a/docs/FAQ.md b/docs/FAQ.md index 5aaa044736..97de0910a4 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -25,7 +25,7 @@ with the desired namespace and service account. Make sure to grant the service a * Make sure you have configured the event source correctly. * Check the event-source pod's containers logs. -Note: You can set the environment variable `DEBUG_LOG:true` in any of the containers to output debug logs. See [here](https://github.com/argoproj/argo-events/blob/master/examples/sensors/log-debug.yaml) for a debug example. +Note: You can set the environment variable `LOG_LEVEL:info/debug/error` in any of the containers to output debug logs. See [here](https://github.com/argoproj/argo-events/blob/master/examples/sensors/log-debug.yaml) for a debug example. **Q. The event-source pod is receiving events but nothing happens.** diff --git a/examples/sensors/log-debug.yaml b/examples/sensors/log-debug.yaml index 6d57a136b4..b909734ac7 100644 --- a/examples/sensors/log-debug.yaml +++ b/examples/sensors/log-debug.yaml @@ -6,8 +6,8 @@ spec: template: container: env: - - name: DEBUG_LOG - value: "true" + - name: LOG_LEVEL + value: error dependencies: - name: test-dep eventSourceName: calendar