realTimeLog.js
932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//app.js
// import log from 'utils/realTimeLog'
function str2ab(str) {
let strLen = str.length*2
var buf =new ArrayBuffer(strLen>5000?5000:strLen);
var bufView =new Uint16Array(buf);
for (var i = 0; i < buf.byteLength;i++) {
let asc=str.charCodeAt(i)
bufView[i] = asc;
}
return buf;
}
function ab2str(buf) {
return String.fromCharCode.apply(null,new Uint16Array(buf));
}
if (wx.getRealtimeLogManager) {
const logger = wx.getRealtimeLogManager()
let consoleLog=console.log
function wlog(){
let argumentsX=[...arguments]
return new Promise(function (success,fail) {
let params=""
argumentsX.forEach((val,i)=>{
let str=JSON.stringify(val);
if(!str) return;
params+=str
})
let bs=str2ab(params)
logger.info(ab2str(bs).toString());
success()
})
}
console.log=function () {
consoleLog(...arguments)
wlog(...arguments);
}
}