Closed JohnRoesler closed 3 years ago
Hi @JohnRoesler, thanks, I wasn't aware about this log option. I have been playing with it a bit. What do you think about enabling this by default, without requiring any additional configuration?
I made some modifications and ended up with:
type pahoLogWrapper struct {
ln func(...interface{})
f func(string, ...interface{})
}
func (d pahoLogWrapper) Println(v ...interface{}) {
d.ln(v...)
}
func (d pahoLogWrapper) Printf(format string, v ...interface{}) {
d.f(format, v...)
}
func enableClientLogging() {
l := log.WithField("module", "mqtt")
paho.DEBUG = pahoLogWrapper{l.Debugln, l.Debugf}
paho.ERROR = pahoLogWrapper{l.Errorln, l.Errorf}
paho.WARN = pahoLogWrapper{l.Warningln, l.Warningf}
paho.CRITICAL = pahoLogWrapper{l.Errorln, l.Errorf}
}
For example, the above could be added to the main.go
, like I did for the gRPC logging (https://github.com/brocaar/chirpstack-network-server/blob/master/cmd/chirpstack-network-server/main.go).
Then the paho.<LEVEL> = ....
lines could be added to an init()
function.
I added the l := log.WithField("module", "mqtt")
line to make it easier to understand where the log items are coming from. Maybe over time, this could be considered for all log items in general :)
What do you think?
I do like your implementation. The logs from the paho client were quite noisy, so that would be the only thing I would want to check with this implementation and having them on by default.
The logs from the paho client were quite noisy
I suppose that is only when you enable debug log level? Or did you find the ERROR
, WARN
and CRITICAL
logs also noisy?
@brocaar yes - realized since i was logging all levels to debug, of course it was noisy. I'll update this PR
Thanks @JohnRoesler :+1:
The logs from the paho mqtt client can be very useful in debugging connectivity issues between the bridge and the mqtt broker.