optimized logging

master
cheetah 4 years ago
parent 767e6aee06
commit 87f209a62c

@ -11,6 +11,7 @@ class MessageManager {
if (!routingParams.device) { if (!routingParams.device) {
routingParams.device = 'generic' routingParams.device = 'generic'
} }
//console.log(routingParams)
const msgObj = { const msgObj = {
type, type,
routingParams, routingParams,
@ -30,7 +31,11 @@ class MessageManager {
duplexCapable: false, duplexCapable: false,
deliveryLog: {}, deliveryLog: {},
}) })
console.log('finished msg obj is ', msgObj) console.log(`Type:\t\t${ type }\nDevice:\t\t${ routingParams.device }`)
console.log(`Message UUID:\t${ msgObj.id }`)
console.log(`Connectors:\t${ JSON.parse(JSON.stringify(routingParams.connectors)).map(x=>`${x[0]}=${x.splice(1).join(',')}`).join('&') }`)
console.log(`Message Original Payload:\t"${ payload }"`)
console.log(`Processed Device Payload:\t"${ msgObj.payload }"`)
return msgObj.id return msgObj.id
} }
async msgStatus(msgId, uuid, status) { async msgStatus(msgId, uuid, status) {
@ -53,7 +58,7 @@ class MessageManager {
if (!msg._routerData) throw `No Routerdata attached to msg with id ${ msgId }` if (!msg._routerData) throw `No Routerdata attached to msg with id ${ msgId }`
if (!!msg.locked) throw 'message is locked' if (!!msg.locked) throw 'message is locked'
console.log(msg.routingParams.connectors) //console.log(msg.routingParams.connectors)
let deliveryChain = msg.routingParams.connectors.map((connectorDeliveryTry) => { let deliveryChain = msg.routingParams.connectors.map((connectorDeliveryTry) => {
const connectorName = connectorDeliveryTry[0], const connectorName = connectorDeliveryTry[0],
connectorArgs = connectorDeliveryTry.slice(1), connectorArgs = connectorDeliveryTry.slice(1),
@ -66,15 +71,15 @@ class MessageManager {
res([false, 'timeout']) res([false, 'timeout'])
}, !!connectorConfig && !!connectorConfig.duplexTimeout ? connectorConfig.duplexTimeout*1e3 : 30e3) }, !!connectorConfig && !!connectorConfig.duplexTimeout ? connectorConfig.duplexTimeout*1e3 : 30e3)
ConnectorRegistry.events.once(`msg:status:${ msgId }:failed`, () => { ConnectorRegistry.events.once(`msg:status:${ msgId }:failed`, () => {
console.log(`${ msgId } failed, continuing`) console.log(`${ msgId } failed via ${ connectorName }:${ connectorArgs.join(',') }, continuing...`)
res([false, 'failed']) res([false, 'failed'])
}) })
ConnectorRegistry.events.once(`msg:status:${ msgId }:delivered`, () => { ConnectorRegistry.events.once(`msg:status:${ msgId }:delivered`, () => {
console.log(`${ msgId } delivered`) console.log(`${ msgId } delivered via ${ connectorName }:${ connectorArgs.join(',') }`)
res([true, 'delivered']) res([true, 'delivered'])
}) })
console.log(`Trying to deliver msg#${ msg.id } with ${ JSON.stringify(connectorDeliveryTry) }`) console.log(`Trying to deliver msg#${ msg.id } with ${ connectorName }:${ connectorArgs.join(',') }`)
console.log(this.messages[ msgId ].deliveryLog) //console.log(this.messages[ msgId ].deliveryLog)
ConnectorRegistry.transmit(connectorName, msg, connectorArgs) ConnectorRegistry.transmit(connectorName, msg, connectorArgs)
} }
return chainPromise return chainPromise
@ -89,7 +94,8 @@ class MessageManager {
}) })
.then(($) => { .then(($) => {
this._clearEventHandlers4MsgID(msgId) this._clearEventHandlers4MsgID(msgId)
console.log('DELIVERY WAS A SUCCESS', $, this.messages[ msgId ]._routerData.deliveryLog) const dLog = this.messages[ msgId ]._routerData.deliveryLog
console.log('DELIVERY WAS A SUCCESS', Object.keys(dLog).map(x=>`${ x } is ${ dLog[x] }`).join('\n'))
}) })
.catch(($) => { .catch(($) => {
this._clearEventHandlers4MsgID(msgId) this._clearEventHandlers4MsgID(msgId)

Loading…
Cancel
Save