verbose logging switch
This commit is contained in:
parent
0eede1309f
commit
f536b7a16f
13
src/main.ts
13
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user