Skip to content

Commit 6d0ec92

Browse files
authored
Added log level option configuration (argoproj#3201)
Signed-off-by: Omer Aplatony <[email protected]>
1 parent 2451789 commit 6d0ec92

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

common/common.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
const (
2828
// EnvVarKubeConfig is the path to the Kubernetes configuration
2929
EnvVarKubeConfig = "KUBECONFIG"
30-
// EnvVarDebugLog is the env var to turn on the debug mode for logging
31-
EnvVarDebugLog = "DEBUG_LOG"
30+
// EnvVarLogLog is the env var to select the log level - options are debug, info, error
31+
EnvVarLogLevel = "LOG_LEVEL"
3232
// ENVVarPodName should be set to the name of the pod
3333
EnvVarPodName = "POD_NAME"
3434
// ENVVarLeaderElection sets the leader election mode

common/logging/logger.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ const (
4141
LabelHTTPMethod = "http-method"
4242
LabelTime = "time"
4343
TimestampFormat = "2006-01-02 15:04:05"
44+
InfoLevel = "info"
45+
DebugLevel = "debug"
46+
ErrorLevel = "error"
4447
)
4548

4649
// NewArgoEventsLogger returns a new ArgoEventsLogger
4750
func NewArgoEventsLogger() *zap.SugaredLogger {
48-
var config zap.Config
49-
debugMode, ok := os.LookupEnv(common.EnvVarDebugLog)
50-
if ok && debugMode == "true" {
51-
config = zap.NewDevelopmentConfig()
52-
} else {
53-
config = zap.NewProductionConfig()
54-
}
51+
logLevel, _ := os.LookupEnv(common.EnvVarLogLevel)
52+
config := ConfigureLogLevelLogger(logLevel)
5553
// Config customization goes here if any
5654
config.OutputPaths = []string{"stdout"}
5755
logger, err := config.Build()
@@ -81,3 +79,19 @@ func FromContext(ctx context.Context) *zap.SugaredLogger {
8179
}
8280
return NewArgoEventsLogger()
8381
}
82+
83+
// Returns logger conifg depending on the log level
84+
func ConfigureLogLevelLogger(logLevel string) zap.Config {
85+
logConfig := zap.NewProductionConfig()
86+
switch logLevel {
87+
case InfoLevel:
88+
logConfig.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
89+
case ErrorLevel:
90+
logConfig.Level = zap.NewAtomicLevelAt(zap.ErrorLevel)
91+
case DebugLevel:
92+
logConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
93+
default:
94+
logConfig.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
95+
}
96+
return logConfig
97+
}

docs/FAQ.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ with the desired namespace and service account. Make sure to grant the service a
2525
* Make sure you have configured the event source correctly.
2626
* Check the event-source pod's containers logs.
2727

28-
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.
28+
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.
2929

3030
**Q. The event-source pod is receiving events but nothing happens.**
3131

examples/sensors/log-debug.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ spec:
66
template:
77
container:
88
env:
9-
- name: DEBUG_LOG
10-
value: "true"
9+
- name: LOG_LEVEL
10+
value: error
1111
dependencies:
1212
- name: test-dep
1313
eventSourceName: calendar

0 commit comments

Comments
 (0)