Skip to content

Commit

Permalink
refactor(log): improve the log info
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Dec 29, 2021
1 parent 77e0df3 commit 944627d
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/views/connections/ConnectionsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export default class ConnectionsDetail extends Vue {
this.$message.success(this.$tc('common.deleteSuccess'))
if (res.id) {
this.removeActiveConnection({ id: res.id })
this.$log.info(`MQTTX remove connection ${res.name}(clientID ${res.clientId}) success`)
this.$log.info(`MQTTX remove connection ${res.name} (clientID ${res.clientId}) success`)
}
}
}
Expand Down Expand Up @@ -646,24 +646,23 @@ export default class ConnectionsDetail extends Vue {
// Delete message
private async handleDeleteMessage() {
const connectID = this.record.id
let id = ''
if (this.selectedMessage && this.selectedMessage.id) {
id = this.selectedMessage.id.toString()
}
if (connectID) {
const { messageService } = useServices()
const res: MessageModel | undefined = await messageService.delete(id)
if (res) {
this.showContextmenu = false
this.$message.success(this.$tc('common.deleteSuccess'))
this.$emit('reload')
this.$log.info(`Delete message success, connectID ${connectID}`)
} else {
this.showContextmenu = false
this.$message.error(this.$tc('common.deletefailed'))
this.$log.info('Delete message failed')
}
const { messageService } = useServices()
const res: MessageModel | undefined = await messageService.delete(id)
if (res) {
this.showContextmenu = false
this.$message.success(this.$tc('common.deleteSuccess'))
this.$emit('reload')
this.$log.info(
`Delete message success, Name: ${this.record.name} ClientID: ${this.record.clientId}, Payload: ${res.payload}`,
)
} else {
this.showContextmenu = false
this.$message.error(this.$tc('common.deletefailed'))
this.$log.info('Delete message failed')
}
}
Expand Down Expand Up @@ -773,7 +772,7 @@ export default class ConnectionsDetail extends Vue {
if (this.record.id) {
const { messageService } = useServices()
await messageService.cleanInConnection(this.record.id)
this.$log.info('Cleaned history connection message')
this.$log.info(`${this.record.name} was cleaned history connection messages`)
}
}
Expand Down Expand Up @@ -886,7 +885,7 @@ export default class ConnectionsDetail extends Vue {
this.connectLoading = false
this.client.end!(true)
this.retryTimes = 0
this.$log.info('MQTTX client connection cancel')
this.$log.info(`MQTTX client connection cancel, Name: ${this.record.name}`)
}
// Disconnect
Expand Down Expand Up @@ -916,7 +915,7 @@ export default class ConnectionsDetail extends Vue {
this.setShowClientInfo(true)
}
this.$emit('reload')
this.$log.info(`MQTTX client disconnect, client ID : ${this.record.clientId}`)
this.$log.info(`MQTTX client disconnect, Name: ${this.record.name}, client ID: ${this.record.clientId}`)
})
}
Expand All @@ -938,7 +937,7 @@ export default class ConnectionsDetail extends Vue {
})
this.setShowClientInfo(false)
this.$emit('reload', false, false, this.handleReSubTopics)
this.$log.info('Connect success, MQTT.js onConnect trigger')
this.$log.info(`${this.record.name} connect success, MQTT.js onConnect trigger`)
}
// Error callback
Expand All @@ -957,7 +956,7 @@ export default class ConnectionsDetail extends Vue {
duration: 3000,
offset: 30,
})
this.$log.error(`Connect fail, MQTT.js onError trigger, ${error.stack}`)
this.$log.error(`${this.record.name} connect fail, MQTT.js onError trigger, ${error.stack}`)
this.$emit('reload')
}
Expand All @@ -983,7 +982,7 @@ export default class ConnectionsDetail extends Vue {
this.retryTimes = 0
this.connectLoading = false
} else {
this.$log.info(`Reconnect: ${this.retryTimes} times retry`)
this.$log.info(`${this.record.name} reconnect: ${this.retryTimes} times retry`)
this.retryTimes += 1
this.connectLoading = true
this.$notify({
Expand All @@ -999,7 +998,7 @@ export default class ConnectionsDetail extends Vue {
// Close connection callback
private onClose() {
this.$log.info('Connect close, MQTT.js onClose trigger')
this.$log.info(`${this.record.name} connect close, MQTT.js onClose trigger`)
this.connectLoading = false
this.isReconnect = false
}
Expand Down Expand Up @@ -1037,14 +1036,14 @@ export default class ConnectionsDetail extends Vue {
}
this.setScript({ currentScript })
this.$message.success(this.$tc('script.startScript'))
this.$log.info('Set script successed')
this.$log.info(`${this.record.name} set script successed`)
}
// Remove script
private removeScript() {
this.setScript({ currentScript: null })
this.$message.success(this.$tc('script.stopScirpt'))
this.$log.info('Remove script successed')
this.$log.info(`${this.record.name} remove script successed`)
}
// Recevied message
Expand Down Expand Up @@ -1104,7 +1103,7 @@ export default class ConnectionsDetail extends Vue {
this.messages.push(receivedMessage)
this.messagesAddedNewItem = true
const msgIdLog = JSON.stringify(receivedMessage.id)
let receivedLog = `Message arrived: message added ${msgIdLog} added to topic "${topic}", MQTT.js onMessageArrived trigger`
let receivedLog = `${this.record.name} message arrived: message added ${msgIdLog} added to topic "${topic}", MQTT.js onMessageArrived trigger`
if (this.record.mqttVersion === '5.0') {
const logProperties = JSON.stringify(receivedMessage.properties)
receivedLog += ` with Properties: ${logProperties}`
Expand Down Expand Up @@ -1220,7 +1219,7 @@ export default class ConnectionsDetail extends Vue {
const errorMsg = error.toString()
this.$message.error(errorMsg)
this.stopTimedSend()
this.$log.error(`Client message publish failed, ${error.stack}`)
this.$log.error(`${this.record.name} message publish failed, ${error.stack}`)
return false
}
const properties = this.record.mqttVersion === '5.0' ? props : undefined
Expand Down Expand Up @@ -1250,7 +1249,7 @@ export default class ConnectionsDetail extends Vue {
}
const logPayload = JSON.stringify(publishMessage.payload)
const logTopic = JSON.stringify(publishMessage.topic)
let pubLog = `Sucessfully published message ${logPayload} to topic ${logTopic}`
let pubLog = `${this.record.name} sucessfully published message ${logPayload} to topic ${logTopic}`
if (this.record.mqttVersion === '5.0') {
const logProperties = JSON.stringify(publishMessage.properties)
pubLog += ` with Properties: ${logProperties}`
Expand Down

0 comments on commit 944627d

Please sign in to comment.