diff --git a/src/main.ts b/src/main.ts index b10f2f3..5ada886 100644 --- a/src/main.ts +++ b/src/main.ts @@ -27,6 +27,7 @@ options .option('-t, --topic [topic to subscribe]', 'Topic to subscribe, can appear multiple times', collect, []) .option('-e, --encapsulate', 'store current timestamp, topic and payload in document', false) .option('-p, --parsePayload', 'parse payload when encapsulating (otherwise always)', false) + .option('-v, --verbose', 'log all inserted messages', false) .parse(process.argv) @@ -79,12 +80,16 @@ class MqttMongo extends Events.EventEmitter { if (this.dbReady || true) { while (! this.queue.isEmpty()) { let msg : MqttMessage.MqttMessage = this.queue.deq() - console.info(`Something in the queue: ${JSON.stringify(msg)}`) + if (this.options.verbose) { + console.info(`Something in the queue: ${JSON.stringify(msg)}`) + } let coll = this.dbHandle.collection(this.options.collection) coll.insertOne(msg.getMessage()) .then( (r) => { - console.success(`Successfully inserted into database ${JSON.stringify(msg.getMessage())}`) + if (this.options.verbose) { + console.success(`Successfully inserted into database ${JSON.stringify(msg.getMessage())}`) + } }, (err) => { console.error(`Error when trying to insert into database ${err}`) @@ -122,7 +127,9 @@ class MqttMongo extends Events.EventEmitter { this.mqttClient.on('message', (topic : string, messageBuf : Buffer) => { msgCnt++; let message = messageBuf.toString('UTF-8') - console.info(`Message received ${msgCnt}, topic ${topic}, payload ${message}`) + if (this.options.verbose) { + console.info(`Message received ${msgCnt}, topic ${topic}, payload ${message}`) + } if (topic == "MqttMongo/Command" && message == "shutdown") { this.shutdown()