Skip to content

Commit 2dff731

Browse files
committed
Update logging.
1 parent e0ec321 commit 2dff731

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

backend/mqttpubsub/backend.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewBackend(server, username, password string) (*Backend, error) {
3434
opts.SetOnConnectHandler(b.onConnected)
3535
opts.SetConnectionLostHandler(b.onConnectionLost)
3636

37-
log.WithField("server", server).Info("backend/mqttpubsub: connecting to mqtt broker")
37+
log.WithField("server", server).Info("backend: connecting to mqtt broker")
3838
b.conn = mqtt.NewClient(opts)
3939
if token := b.conn.Connect(); token.Wait() && token.Error() != nil {
4040
return nil, token.Error()
@@ -60,7 +60,7 @@ func (b *Backend) SubscribeGatewayTX(mac lorawan.EUI64) error {
6060
b.mutex.Lock()
6161

6262
topic := fmt.Sprintf("gateway/%s/tx", mac.String())
63-
log.WithField("topic", topic).Info("backend/mqttpubsub: subscribing to topic")
63+
log.WithField("topic", topic).Info("backend: subscribing to topic")
6464
if token := b.conn.Subscribe(topic, 0, b.txPacketHandler); token.Wait() && token.Error() != nil {
6565
return token.Error()
6666
}
@@ -75,7 +75,7 @@ func (b *Backend) UnSubscribeGatewayTX(mac lorawan.EUI64) error {
7575
b.mutex.Lock()
7676

7777
topic := fmt.Sprintf("gateway/%s/tx", mac.String())
78-
log.WithField("topic", topic).Info("backend/mqttpubsub: unsubscribing from topic")
78+
log.WithField("topic", topic).Info("backend: unsubscribing from topic")
7979
if token := b.conn.Unsubscribe(topic); token.Wait() && token.Error() != nil {
8080
return token.Error()
8181
}
@@ -100,18 +100,18 @@ func (b *Backend) publish(topic string, v interface{}) error {
100100
if err != nil {
101101
return err
102102
}
103-
log.WithField("topic", topic).Info("backend/mqttpubsub: publishing packet")
103+
log.WithField("topic", topic).Info("backend: publishing packet")
104104
if token := b.conn.Publish(topic, 0, false, bytes); token.Wait() && token.Error() != nil {
105105
return token.Error()
106106
}
107107
return nil
108108
}
109109

110110
func (b *Backend) txPacketHandler(c mqtt.Client, msg mqtt.Message) {
111-
log.WithField("topic", msg.Topic()).Info("backend/mqttpubsub: packet received")
111+
log.WithField("topic", msg.Topic()).Info("backend: packet received")
112112
var txPacket models.TXPacket
113113
if err := json.Unmarshal(msg.Payload(), &txPacket); err != nil {
114-
log.Errorf("backend/mqttpubsub: decode tx packet error: %s", err)
114+
log.Errorf("backend: decode tx packet error: %s", err)
115115
return
116116
}
117117
b.txPacketChan <- txPacket
@@ -121,16 +121,16 @@ func (b *Backend) onConnected(c mqtt.Client) {
121121
defer b.mutex.RUnlock()
122122
b.mutex.RLock()
123123

124-
log.Info("backend/mqttpubsub: connected to mqtt broker")
124+
log.Info("backend: connected to mqtt broker")
125125
if len(b.gateways) > 0 {
126126
for {
127-
log.WithField("topic_count", len(b.gateways)).Info("backend/mqttpubsub: re-registering to gateway topics")
127+
log.WithField("topic_count", len(b.gateways)).Info("backend: re-registering to gateway topics")
128128
topics := make(map[string]byte)
129129
for k := range b.gateways {
130130
topics[fmt.Sprintf("gateway/%s/tx", k)] = 0
131131
}
132132
if token := b.conn.SubscribeMultiple(topics, b.txPacketHandler); token.Wait() && token.Error() != nil {
133-
log.WithField("topic_count", len(topics)).Errorf("backend/mqttpubsub: subscribe multiple failed: %s", token.Error())
133+
log.WithField("topic_count", len(topics)).Errorf("backend: subscribe multiple failed: %s", token.Error())
134134
time.Sleep(time.Second)
135135
continue
136136
}
@@ -140,5 +140,5 @@ func (b *Backend) onConnected(c mqtt.Client) {
140140
}
141141

142142
func (b *Backend) onConnectionLost(c mqtt.Client, reason error) {
143-
log.Errorf("backend/mqttpubsub: mqtt connection error: %s", reason)
143+
log.Errorf("backend: mqtt connection error: %s", reason)
144144
}

0 commit comments

Comments
 (0)