fix(inputs.mqtt_consumer): Restore trace logging option (#15670)

This commit is contained in:
Joshua Powers 2024-07-29 02:42:40 -06:00 committed by GitHub
parent f57d6764cf
commit f9900f8787
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -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
@ -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")
}

View File

@ -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...)
}