Skip to content

Commit

Permalink
feat: add better logging for mqtt (#444)
Browse files Browse the repository at this point in the history
Co-authored-by: Khuda Dad Nomani <[email protected]>
  • Loading branch information
kaushik-rishi and KhudaDad414 authored Jul 31, 2023
1 parent 9836cdc commit 18cded6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/adapters/mqtt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Adapter from '../../lib/adapter.js'
import GleeMessage from '../../lib/message.js'
import { MqttAuthConfig, MqttAdapterConfig } from '../../lib/index.js'
import { SecurityScheme } from '@asyncapi/parser'
import { logLineWithIcon } from '../../lib/logger.js'

interface IMQTTHeaders {
cmd?: string
Expand Down Expand Up @@ -130,6 +131,19 @@ class MqttAdapter extends Adapter {
const binding = operation.binding('mqtt')
this.client.subscribe(channel, {
qos: binding?.qos ? binding.qos : 0,
}, (err, granted) => {
if (err) {
logLineWithIcon('x', `Error while trying to subscribe to \`${channel}\` topic.`, {
highlightedWords: [channel],
iconColor: '#f00',
disableEmojis: true,
})
console.log(err.message)
return
}
logLineWithIcon(':zap:', `Subscribed to \`${channel}\` topic with QoS ${granted?.[0].qos}`, {
highlightedWords: [channel],
})
})
})
}
Expand Down

0 comments on commit 18cded6

Please sign in to comment.