Skip to content

Commit 1838fcd

Browse files
authored
Implement paho mqtt client logging (#182)
1 parent 1062b1d commit 1838fcd

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

cmd/chirpstack-gateway-bridge/cmd/configfile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ marshaler="{{ .Integration.Marshaler }}"
227227
# Keep alive will set the amount of time (in seconds) that the client should
228228
# wait before sending a PING request to the broker. This will allow the client
229229
# to know that a connection has not been lost with the server.
230+
# Valid units are 'ms', 's', 'm', 'h'. Note that these values can be combined, e.g. '24h30m15s'.
230231
keep_alive="{{ .Integration.MQTT.KeepAlive }}"
231232
232233
# Maximum interval that will be waited between reconnection attempts when connection is lost.

cmd/chirpstack-gateway-bridge/main.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
package main
22

3-
import "github.com/brocaar/chirpstack-gateway-bridge/cmd/chirpstack-gateway-bridge/cmd"
3+
import (
4+
"github.com/brocaar/chirpstack-gateway-bridge/cmd/chirpstack-gateway-bridge/cmd"
5+
paho "github.com/eclipse/paho.mqtt.golang"
6+
log "github.com/sirupsen/logrus"
7+
)
8+
9+
type pahoLogWrapper struct {
10+
ln func(...interface{})
11+
f func(string, ...interface{})
12+
}
13+
14+
func (d pahoLogWrapper) Println(v ...interface{}) {
15+
d.ln(v...)
16+
}
17+
18+
func (d pahoLogWrapper) Printf(format string, v ...interface{}) {
19+
d.f(format, v...)
20+
}
21+
22+
func enableClientLogging() {
23+
l := log.WithField("module", "mqtt")
24+
paho.DEBUG = pahoLogWrapper{l.Debugln, l.Debugf}
25+
paho.ERROR = pahoLogWrapper{l.Errorln, l.Errorf}
26+
paho.WARN = pahoLogWrapper{l.Warningln, l.Warningf}
27+
paho.CRITICAL = pahoLogWrapper{l.Errorln, l.Errorf}
28+
}
29+
30+
func init() {
31+
enableClientLogging()
32+
}
433

534
var version string // set by the compiler
635

0 commit comments

Comments
 (0)