Skip to content

Commit

Permalink
fix(inputs.mqtt_consumer): Restore trace logging option (#15670)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored Jul 29, 2024
1 parent f57d676 commit f9900f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/inputs/mqtt_consumer/mqtt_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type MQTTConsumer struct {
PingTimeout config.Duration `toml:"ping_timeout"`
MaxUndeliveredMessages int `toml:"max_undelivered_messages"`
PersistentSession bool `toml:"persistent_session"`
ClientTrace bool `toml:"client_trace"`
ClientID string `toml:"client_id"`
Log telegraf.Logger `toml:"-"`
tls.ClientConfig
Expand Down Expand Up @@ -87,6 +88,14 @@ func (m *MQTTConsumer) SetParser(parser telegraf.Parser) {
m.parser = parser
}
func (m *MQTTConsumer) Init() error {
if m.ClientTrace {
log := &mqttLogger{m.Log}
mqtt.ERROR = log
mqtt.CRITICAL = log
mqtt.WARN = log
mqtt.DEBUG = log
}

if m.PersistentSession && m.ClientID == "" {
return errors.New("persistent_session requires client_id")
}
Expand Down
16 changes: 16 additions & 0 deletions plugins/inputs/mqtt_consumer/mqtt_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mqtt_consumer

import (
"github.com/influxdata/telegraf"
)

type mqttLogger struct {
telegraf.Logger
}

func (l mqttLogger) Printf(fmt string, args ...interface{}) {
l.Logger.Debugf(fmt, args...)
}
func (l mqttLogger) Println(args ...interface{}) {
l.Logger.Debug(args...)
}

0 comments on commit f9900f8

Please sign in to comment.