From 18cded629e83ea1ae0104f0e27b064771a6caf6c Mon Sep 17 00:00:00 2001 From: Rishi <52498617+kaushik-rishi@users.noreply.github.com> Date: Mon, 31 Jul 2023 13:27:16 +0530 Subject: [PATCH] feat: add better logging for mqtt (#444) Co-authored-by: Khuda Dad Nomani <32505158+KhudaDad414@users.noreply.github.com> --- src/adapters/mqtt/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/adapters/mqtt/index.ts b/src/adapters/mqtt/index.ts index 188cf4b1f..0cb42f1b1 100644 --- a/src/adapters/mqtt/index.ts +++ b/src/adapters/mqtt/index.ts @@ -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 @@ -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], + }) }) }) }