Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new env var LOG_LEVEL to set logging levels #68

Merged
merged 1 commit into from Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions deploy-all-in-one.yaml
Expand Up @@ -218,6 +218,9 @@ spec:
env:
- name: CONFIG_PATH
value: "/config/"
# set one of the log levels- info, warn, debug, error, fatal, panic
- name: LOG_LEVEL
value: "info"
volumes:
- name: config-volume
configMap:
Expand Down
2 changes: 2 additions & 0 deletions helm/botkube/templates/deployment.yaml
Expand Up @@ -34,6 +34,8 @@ spec:
env:
- name: CONFIG_PATH
value: "/config/"
- name: LOG_LEVEL
value: {{ .Values.logLevel | quote }}
volumes:
- name: config-volume
configMap:
Expand Down
3 changes: 3 additions & 0 deletions helm/botkube/values.yaml
Expand Up @@ -12,6 +12,9 @@ image:
nameOverride: ""
fullnameOverride: ""

# set one of the log levels- info, warn, debug, error, fatal, panic
logLevel: info

config:
## Resources you want to watch
resources:
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Expand Up @@ -88,7 +88,7 @@ func RegisterInformers(c *config.Config) {

// Register informers for k8s events
if len(c.Events.Types) > 0 {
log.Logger.Info("Registering kubernetes events informer")
log.Logger.Infof("Registering kubernetes events informer for types: %+v", c.Events.Types)
watchlist := cache.NewListWatchFromClient(
utils.KubeClient.CoreV1().RESTClient(), "events", apiV1.NamespaceAll, fields.Everything())

Expand All @@ -112,7 +112,7 @@ func RegisterInformers(c *config.Config) {
// Filter and forward
if (utils.AllowedEventKindsMap[utils.EventKind{kind, "all"}] ||
utils.AllowedEventKindsMap[utils.EventKind{kind, ns}]) && (utils.AllowedEventTypesMap[eType]) {
log.Logger.Infof("Processing add to events: %s. Invoked Object: %s:%s", key, eventObj.InvolvedObject.Kind, eventObj.InvolvedObject.Namespace)
log.Logger.Debugf("Processing add to events: %s. Invoked Object: %s:%s", key, eventObj.InvolvedObject.Kind, eventObj.InvolvedObject.Namespace)
sendEvent(obj, c, "events", "create", err)
}
},
Expand Down
7 changes: 6 additions & 1 deletion pkg/logging/logging.go
Expand Up @@ -14,6 +14,11 @@ func init() {
Logger.SetOutput(os.Stdout)

// Only log the warning severity or above.
Logger.SetLevel(logrus.DebugLevel)
logLevel, err := logrus.ParseLevel(os.Getenv("LOG_LEVEL"))
if err != nil {
// Set Info level as a default
logLevel = logrus.InfoLevel
}
Logger.SetLevel(logLevel)
Logger.Formatter = &logrus.TextFormatter{ForceColors: true, FullTimestamp: true}
}
3 changes: 3 additions & 0 deletions pkg/notify/elasticsearch.go
Expand Up @@ -54,6 +54,9 @@ func init() {
if err != nil {
log.Logger.Fatal(fmt.Sprintf("Error in loading configuration. Error:%s", err.Error()))
}
if !c.Communications.ElasticSearch.Enable {
return
}
// create elasticsearch client
elsClient, err = elastic.NewClient(elastic.SetURL(c.Communications.ElasticSearch.Server), elastic.SetBasicAuth(c.Communications.ElasticSearch.Username, c.Communications.ElasticSearch.Password), elastic.SetSniff(false), elastic.SetHealthcheck(false), elastic.SetGzip(true))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Expand Up @@ -130,7 +130,7 @@ func createMaps() {
AllowedEventTypesMap[strings.ToLower(t)] = true
}

log.Logger.Info("AllowedEventKindsMap:: %+v", AllowedEventKindsMap)
log.Logger.Infof("Allowed Events - %+v", AllowedEventKindsMap)
}

// GetObjectMetaData returns metadata of the given object
Expand Down