使用electron桌面应用打印移动端log
- 对于移动端真机测试来说,想看见log是一件很困扰的事情,所以我写了这个项目来帮助自己
- 项目中我输出了请求的内容,时间,和它的级别
- debug (对应level为1)
- info (对应level为2)
- warn (对应level为3)
- error (对应level为4)
- fatal (对应level为5)
git地址
https://github.com/wujiabao123/desk-logger.git
使用时需要调用相应的函数
export default testElectron = {
debug: function (data, date) {
fetch('http://localhost:3000/log', {
credentials: 'include',
mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
body: JSON.stringify({ "level": 1, date, message: data })
})
},
info: function (data, date) {
fetch('http://localhost:3000/log', {
credentials: 'include',
mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
body: JSON.stringify({ "level": 2, date, message: data })
})
},
warn: function (data, date) {
fetch('http://localhost:3000/log', {
credentials: 'include',
mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
body: JSON.stringify({ "level": 3, date, message: data })
})
},
error: function (data, date) {
fetch('http://localhost:3000/log', {
credentials: 'include',
mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
body: JSON.stringify({ "level": 4, date, message: data })
})
},
fatal: function (data, date) {
fetch('http://localhost:3000/log', {
credentials: 'include',
mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
body: JSON.stringify({ "level": 5, date, message: data })
})
}
}