提交 2867edc8 作者: 毛细亚

创建日志

上级 6e238ba8
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>company_app</title><script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script><script defer="defer" src="static/js/chunk-vendors.68d406e7.js"></script><script defer="defer" src="static/js/app.fc60a8f1.js"></script><link href="static/css/chunk-vendors.34a02360.css" rel="stylesheet"><link href="static/css/app.edfd37dc.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but company_app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html> <!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>company_app</title><script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script><script defer="defer" src="static/js/chunk-vendors.00452471.js"></script><script defer="defer" src="static/js/app.8f259f12.js"></script><link href="static/css/chunk-vendors.34a02360.css" rel="stylesheet"><link href="static/css/app.edfd37dc.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but company_app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
\ No newline at end of file \ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"@aliyun-sls/web-track-browser": "^0.0.3",
"@wecom/jssdk": "^2.3.1", "@wecom/jssdk": "^2.3.1",
"axios": "^1.9.0", "axios": "^1.9.0",
"babel-plugin-component": "^1.1.1", "babel-plugin-component": "^1.1.1",
......
...@@ -8,6 +8,9 @@ importers: ...@@ -8,6 +8,9 @@ importers:
.: .:
dependencies: dependencies:
'@aliyun-sls/web-track-browser':
specifier: ^0.0.3
version: 0.0.3
'@wecom/jssdk': '@wecom/jssdk':
specifier: ^2.3.1 specifier: ^2.3.1
version: 2.3.1 version: 2.3.1
...@@ -100,6 +103,9 @@ packages: ...@@ -100,6 +103,9 @@ packages:
resolution: {integrity: sha512-7s0VcTwiK/0tNOVdSX9FWMeFdOEcsAOz9HesBldXxFMaGvIak7KC2z9tV9EgsQXn6KUsWsfIkViMNuIo0GoZDQ==} resolution: {integrity: sha512-7s0VcTwiK/0tNOVdSX9FWMeFdOEcsAOz9HesBldXxFMaGvIak7KC2z9tV9EgsQXn6KUsWsfIkViMNuIo0GoZDQ==}
engines: {node: 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 19 || 20 || 21 || 22} engines: {node: 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 19 || 20 || 21 || 22}
'@aliyun-sls/web-track-browser@0.0.3':
resolution: {integrity: sha512-RYJaZN2A8TKTHsem29B/8IRvjBk4ow0IjrzsTlEfxJtUoRIgtKpI6pEgvtI2LKUqN1/vEz6WzzFA+zttMSN3Fw==}
'@ampproject/remapping@2.3.0': '@ampproject/remapping@2.3.0':
resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==}
engines: {node: '>=6.0.0'} engines: {node: '>=6.0.0'}
...@@ -5390,6 +5396,8 @@ snapshots: ...@@ -5390,6 +5396,8 @@ snapshots:
event-pubsub: 4.3.0 event-pubsub: 4.3.0
js-message: 1.0.7 js-message: 1.0.7
'@aliyun-sls/web-track-browser@0.0.3': {}
'@ampproject/remapping@2.3.0': '@ampproject/remapping@2.3.0':
dependencies: dependencies:
'@jridgewell/gen-mapping': 0.3.8 '@jridgewell/gen-mapping': 0.3.8
......
...@@ -19,10 +19,20 @@ import BiElementUi from 'bi-element-ui' ...@@ -19,10 +19,20 @@ import BiElementUi from 'bi-element-ui'
// import 'bi-element-ui/lib/bi-element-ui.css' // import 'bi-element-ui/lib/bi-element-ui.css'
import uploading from '@/utils/cos-upload' import uploading from '@/utils/cos-upload'
import 'element-ui/lib/theme-chalk/index.css'; import 'element-ui/lib/theme-chalk/index.css';
import errorHandle from '@/utils/errorHandle'
if(process.env.NODE_ENV !== 'production'){ import { getParams } from '@/utils/index'
if(isTest()){
new VConsole(); new VConsole();
} }
function isTest(){
return process.env.NODE_ENV !== 'production'
}
// 开发环境不收集日志
if (process.env.NODE_ENV !== 'development') {
errorHandle.onload()
}
// 测试一下 // 测试一下
Vue.use(uploading) Vue.use(uploading)
Vue.use(BiElementUi, { Vue.use(BiElementUi, {
......
import SlsTracker from '@aliyun-sls/web-track-browser'
import Vue from 'vue'
// https://www.jb51.net/article/245438.htm
export default {
tracker: {},
windowErrors: [],
vueErrors: [],
time: null,
time1: null,
removeDp (arr) {
const obj = {}
const newArray = arr.reduce((pre, cur) => {
if (!obj[cur.error.stack]) {
obj[cur.error.stack] = true
pre.push(cur)
}
return pre
}, [])
return newArray
},
removeDp2 (arr) {
const obj = {}
const newArray = arr.reduce((pre, cur) => {
if (!obj[cur.message]) {
obj[cur.message] = true
pre.push(cur)
}
return pre
}, [])
return newArray
},
onload() {
this.initTrack()
Vue.config.errorHandler = (error, vm, info) => {
// err,错误对象
// vm,发生错误的组件实例
// info,Vue特定的错误信息,例如错误发生的生命周期、错误发生的事件
this.vueErrors.push({ type: 'VueError', info, error, stack: error.stack || '无法捕获错误', element: vm.$vnode.tag, data: vm._data })
if (this.time != null) {
clearTimeout(this.time)
}
this.time = setTimeout(() => {
if (this.vueErrors.length > 0) {
const list = this.removeDp(this.vueErrors)
console.log('vue错误', list)
this.sendError(list)
this.vueErrors = []
}
}, 3000)
}
// 由于errorHandler是全局配置的,因此window.onerror将会“失效”,即errorHandler能捕获的错误,onerror将不能捕获;errorHandler不能捕获的异常,onerror将捕获错误。如果errorCaptured函数返回为false,那么此error将不会传到errorHandler
// window.onerror = (message, source, lineno, colno, error) => {
// // message: 错误信息
// // source:发生错误的资源
// // line:发生错误的行号
// // column:发生错误的列数
// // error:Error错误对象
// this.windowErrors.push({ type: 'windowError', content: { message, source, lineno, colno, error: error.stack || '无法捕获错误' }})
// if (this.time1 != null) {
// clearTimeout(this.time1)
// }
// this.time1 = setTimeout(() => {
// if (this.windowErrors.length > 0) {
// const list = this.removeDp2(this.windowErrors)
// console.log('window错误', list)
// this.sendError(list)
// this.windowErrors = []
// }
// }, 3000)
// }
},
initTrack() {
const opts = {
host: 'cn-hangzhou.log.aliyuncs.com',
project: 'zwwl2022',
logstore: 'frontend_log',
time: 3, // 发送日志的时间间隔,默认是10秒。
count: 100, // 发送日志的数量大小,默认是10条。
topic: '掌微侧边栏' // 自定义日志主题。
}
this.tracker = new SlsTracker(opts)
Vue.prototype.$tracker = this.tracker
},
sendError(data) {
this.tracker.sendBatchLogs(data)
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论