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