feat: 添加插件日志
This commit is contained in:
parent
a7d4cd28f2
commit
8d947a4f02
40
log.js
40
log.js
@ -1,40 +1,66 @@
|
||||
import { isReportLog } from '@/starCloud/starCloud'
|
||||
import { useStarCloudStore } from '@/starCloud/starCloud'
|
||||
|
||||
const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null
|
||||
const logManager = wx.getRealtimeLogManager()
|
||||
|
||||
export default {
|
||||
debug() {
|
||||
if (!log) return
|
||||
if (!isReportLog) return
|
||||
const $starCloud = useStarCloudStore()
|
||||
if (!$starCloud.isReportLog) return
|
||||
const logger = logManager.tag(arguments[0].name)
|
||||
logger.info(arguments[0].message, arguments[0])
|
||||
// eslint-disable-next-line prefer-spread,prefer-rest-params
|
||||
log.debug.apply(log, arguments)
|
||||
},
|
||||
info() {
|
||||
console.log(11111, arguments)
|
||||
if (!log) return
|
||||
if (!isReportLog) return
|
||||
const $starCloud = useStarCloudStore()
|
||||
console.log(111112, arguments)
|
||||
if (!$starCloud.isReportLog) return
|
||||
console.log(111113, arguments)
|
||||
const logger = logManager.tag(arguments[0].name)
|
||||
logger.info(arguments[0].message, arguments[0])
|
||||
// eslint-disable-next-line prefer-spread,prefer-rest-params
|
||||
log.info.apply(log, arguments)
|
||||
},
|
||||
warn() {
|
||||
if (!log) return
|
||||
if (!isReportLog) return
|
||||
const $starCloud = useStarCloudStore()
|
||||
if (!$starCloud.isReportLog) return
|
||||
const logger = logManager.tag(arguments[0].name)
|
||||
logger.warn(arguments[0].message, arguments[0])
|
||||
// eslint-disable-next-line prefer-spread,prefer-rest-params
|
||||
log.warn.apply(log, arguments)
|
||||
},
|
||||
error() {
|
||||
if (!log) return
|
||||
if (!isReportLog) return
|
||||
const $starCloud = useStarCloudStore()
|
||||
if (!$starCloud.isReportLog) return
|
||||
const logger = logManager.tag(arguments[0].name)
|
||||
logger.error(arguments[0].message, arguments[0])
|
||||
// eslint-disable-next-line prefer-spread,prefer-rest-params
|
||||
log.error.apply(log, arguments)
|
||||
},
|
||||
setFilterMsg(msg) {
|
||||
// 从基础库2.7.3开始支持
|
||||
if (!log || !log.setFilterMsg) return
|
||||
if (typeof msg !== 'string') return
|
||||
if (!isReportLog) return
|
||||
const $starCloud = useStarCloudStore()
|
||||
if (!$starCloud.isReportLog) return
|
||||
const logger = logManager.tag(arguments[0].name)
|
||||
logger.setFilterMsg(JSON.stringify(arguments[0]))
|
||||
log.setFilterMsg(msg)
|
||||
},
|
||||
addFilterMsg(msg) {
|
||||
// 从基础库2.8.1开始支持
|
||||
if (!log || !log.addFilterMsg) return
|
||||
if (typeof msg !== 'string') return
|
||||
if (!isReportLog) return
|
||||
const $starCloud = useStarCloudStore()
|
||||
if (!$starCloud.isReportLog) return
|
||||
const logger = logManager.tag(arguments[0].name)
|
||||
logger.addFilterMsg(JSON.stringify(arguments[0]))
|
||||
log.addFilterMsg(msg)
|
||||
}
|
||||
}
|
||||
|
||||
83
starCloud.js
83
starCloud.js
@ -296,7 +296,7 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
lockList[accountInfo.uid] = [this.lockInfo]
|
||||
setStorage('starLockList', lockList)
|
||||
}
|
||||
} else {
|
||||
} else if (code === Result.Fail.code) {
|
||||
const lockList = getStorage('starLockList')
|
||||
if (lockList[accountInfo.uid]) {
|
||||
const index = lockList[accountInfo.uid].findIndex(item => item.lockId === lockId)
|
||||
@ -319,8 +319,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
async openDoor(params) {
|
||||
const { accountInfo, type } = params
|
||||
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
Result.Success.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -329,8 +329,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`开始开门`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
|
||||
// 设置执行账号
|
||||
const result = await this.login(accountInfo)
|
||||
@ -338,8 +339,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
return result
|
||||
}
|
||||
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
result.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -348,16 +349,17 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`登录星云账号: ${result.message}`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
|
||||
// 确认设备连接正常
|
||||
if (!params.connected) {
|
||||
const searchResult = await searchAndConnectDevice(
|
||||
this.lockInfo.bluetooth.bluetoothDeviceName
|
||||
)
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
searchResult.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -366,8 +368,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`连接设备: ${searchResult.message}`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
if (searchResult.code !== Result.Success.code) {
|
||||
return searchResult
|
||||
}
|
||||
@ -380,8 +383,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
return checkResult
|
||||
}
|
||||
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
checkResult.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -390,8 +393,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`确认是否为锁用户: ${checkResult.message}`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
|
||||
// 是否需要联网
|
||||
let onlineToken = ''
|
||||
@ -404,8 +408,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
}
|
||||
}
|
||||
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
checkResult.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -414,8 +418,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`判断是否需要联网token: ${this.lockInfo.lockSetting.appUnlockOnline}`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
|
||||
// 开门方式
|
||||
let openMode
|
||||
@ -473,8 +478,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
|
||||
const packageArray = createPackageEnd(headArray, cebArray)
|
||||
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
Result.Success.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -483,8 +488,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`开始写入`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
|
||||
const writeResult = await writeBLECharacteristicValue(
|
||||
this.lockInfo.deviceId,
|
||||
@ -497,8 +503,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
return writeResult
|
||||
}
|
||||
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
writeResult.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -507,8 +513,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`写入完成:${writeResult.message}`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
|
||||
return this.getWriteResult(this.openDoor, params)
|
||||
},
|
||||
@ -1573,8 +1580,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
characteristicValueCallback = async data => {
|
||||
// code 6 token过期,重新获取
|
||||
if (data.code === Result.NotTokenLock.code) {
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
data.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -1582,8 +1589,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`token过期:${data.message}`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
resolve(await request({ ...params, connected: true }))
|
||||
} else if (data.code === Result.NotRegisteredLock.code) {
|
||||
const checkResult = await this.checkLockUser(true)
|
||||
@ -1599,8 +1607,8 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
await this.disconnectDevice()
|
||||
}
|
||||
console.log('写入结果', data, request, params)
|
||||
log.info(
|
||||
new Result(
|
||||
log.info({
|
||||
...new Result(
|
||||
data.code,
|
||||
{
|
||||
lockName: this.lockInfo.bluetooth.bluetoothDeviceName,
|
||||
@ -1608,8 +1616,9 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
`开门结果:${data.message}`
|
||||
)
|
||||
)
|
||||
),
|
||||
name: 'openDoor'
|
||||
})
|
||||
resolve(data)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user