-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert kafka debug-logging to trace level
- Loading branch information
Showing
5 changed files
with
54 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
package kafka | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/IBM/sarama" | ||
|
||
"github.com/influxdata/telegraf" | ||
"github.com/influxdata/telegraf/logger" | ||
) | ||
|
||
type Logger struct { | ||
} | ||
var ( | ||
log = logger.New("sarama", "", "") | ||
once sync.Once | ||
) | ||
|
||
// DebugLogger logs messages from sarama at the debug level. | ||
type DebugLogger struct { | ||
Log telegraf.Logger | ||
} | ||
type debugLogger struct{} | ||
|
||
func (l *DebugLogger) Print(v ...interface{}) { | ||
l.Log.Debug(v...) | ||
func (l *debugLogger) Print(v ...interface{}) { | ||
log.Trace(v...) | ||
} | ||
|
||
func (l *DebugLogger) Printf(format string, v ...interface{}) { | ||
l.Log.Debugf(format, v...) | ||
func (l *debugLogger) Printf(format string, v ...interface{}) { | ||
log.Tracef(format, v...) | ||
} | ||
|
||
func (l *DebugLogger) Println(v ...interface{}) { | ||
func (l *debugLogger) Println(v ...interface{}) { | ||
l.Print(v...) | ||
} | ||
|
||
// SetLogger configures a debug logger for kafka (sarama) | ||
func (k *Logger) SetLogger() { | ||
sarama.Logger = &DebugLogger{Log: logger.New("sarama", "", "")} | ||
func SetLogger(level telegraf.LogLevel) { | ||
// Set-up the sarama logger only once | ||
once.Do(func() { | ||
sarama.Logger = &debugLogger{} | ||
}) | ||
// Increase the log-level if needed. | ||
if !log.Level().Includes(level) { | ||
log.SetLevel(level) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters