fix(inputs.mqtt_consumer): Restore trace logging option (#15670)
This commit is contained in:
parent
f57d6764cf
commit
f9900f8787
|
|
@ -58,6 +58,7 @@ type MQTTConsumer struct {
|
||||||
PingTimeout config.Duration `toml:"ping_timeout"`
|
PingTimeout config.Duration `toml:"ping_timeout"`
|
||||||
MaxUndeliveredMessages int `toml:"max_undelivered_messages"`
|
MaxUndeliveredMessages int `toml:"max_undelivered_messages"`
|
||||||
PersistentSession bool `toml:"persistent_session"`
|
PersistentSession bool `toml:"persistent_session"`
|
||||||
|
ClientTrace bool `toml:"client_trace"`
|
||||||
ClientID string `toml:"client_id"`
|
ClientID string `toml:"client_id"`
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
|
@ -87,6 +88,14 @@ func (m *MQTTConsumer) SetParser(parser telegraf.Parser) {
|
||||||
m.parser = parser
|
m.parser = parser
|
||||||
}
|
}
|
||||||
func (m *MQTTConsumer) Init() error {
|
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 == "" {
|
if m.PersistentSession && m.ClientID == "" {
|
||||||
return errors.New("persistent_session requires client_id")
|
return errors.New("persistent_session requires client_id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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...)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue