Skip to content

Commit

Permalink
feat(outputs.mqtt): Add client trace logging
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed May 30, 2024
1 parent d89aef8 commit e39e52b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/outputs/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sync"
"time"

mqttLib "github.com/eclipse/paho.mqtt.golang"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/internal"
Expand All @@ -28,6 +30,7 @@ type message struct {
type MQTT struct {
TopicPrefix string `toml:"topic_prefix" deprecated:"1.25.0;use 'topic' instead"`
Topic string `toml:"topic"`
ClientTrace bool `toml:"client_trace"`
BatchMessage bool `toml:"batch" deprecated:"1.25.2;use 'layout = \"batch\"' instead"`
Layout string `toml:"layout"`
HomieDeviceName string `toml:"homie_device_name"`
Expand All @@ -51,6 +54,14 @@ func (*MQTT) SampleConfig() string {
}

func (m *MQTT) Init() error {
if m.ClientTrace {
log := &mqttLogger{m.Log}
mqttLib.ERROR = log
mqttLib.CRITICAL = log
mqttLib.WARN = log
mqttLib.DEBUG = log
}

if len(m.Servers) == 0 {
return errors.New("no servers specified")
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/outputs/mqtt/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
## actually reads it
# retain = false

## Client trace messages
## When set to true, and debug mode enabled in the agent settings, the MQTT
## client's messages are included in telegraf logs. These messages are very
## noisey, but essential for debugging issues.
# client_trace = false

## Layout of the topics published.
## The following choices are available:
## non-batch -- send individual messages, one for each metric
Expand Down

0 comments on commit e39e52b

Please sign in to comment.