Skip to content

Commit

Permalink
Determine log level for kafka output (#5397)
Browse files Browse the repository at this point in the history
* Determine log level for kafka output

* Add description to changelog

* Add pull request reference in changelog

* Fix code import style
  • Loading branch information
mrauter authored and kvch committed Oct 24, 2017
1 parent f40b49a commit 27a2f2d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di

*Affecting all Beats*

- Determine log level for kafka output. {pull}5397[5397]

*Auditbeat*

*Filebeat*
Expand Down
35 changes: 28 additions & 7 deletions libbeat/outputs/kafka/log.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
package kafka

import "github.com/elastic/beats/libbeat/logp"
import (
"github.com/Shopify/sarama"

"github.com/elastic/beats/libbeat/logp"
)

type kafkaLogger struct{}

func (kafkaLogger) Print(v ...interface{}) {
logp.Warn("kafka message: %v", v...)
func (kl kafkaLogger) Print(v ...interface{}) {
kl.Log("kafka message: %v", v)
}

func (kl kafkaLogger) Printf(format string, v ...interface{}) {
kl.Log(format, v)
}

func (kafkaLogger) Printf(format string, v ...interface{}) {
logp.Warn(format, v...)
func (kl kafkaLogger) Println(v ...interface{}) {
kl.Log("kafka message: %v", v...)
}

func (kafkaLogger) Println(v ...interface{}) {
logp.Warn("kafka message: %v", v...)
func (kafkaLogger) Log(format string, v ...interface{}) {
warn := false
for _, val := range v {
if err, ok := val.(sarama.KError); ok {
if err != sarama.ErrNoError {
warn = true
break
}
}
}
if warn {
logp.Warn(format, v)
} else {
logp.Info(format, v)
}
}

0 comments on commit 27a2f2d

Please sign in to comment.