Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/themusecatcher/amazing-monitor
日志监控库
https://github.com/themusecatcher/amazing-monitor
Last synced: 15 days ago
JSON representation
日志监控库
- Host: GitHub
- URL: https://github.com/themusecatcher/amazing-monitor
- Owner: themusecatcher
- Created: 2023-10-08T06:21:31.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-11T07:03:46.000Z (over 1 year ago)
- Last Synced: 2024-11-09T08:21:19.391Z (2 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Amazing Monitor
日志监控库
## 安装
```bash
pnpm i amazing-monitor user-agent
# or
npm install amazing-monitor user-agent
# or
yarn add amazing-monitor user-agent
```## 创建实例
- 创建 `src/monitor.js`
```js
import Monitor from 'amazing-monitor'
const userAgent = require('user-agent')
var apiUrl
const host = window.location.host
if (host === 'www.test.cn') { // 测试域名
apiUrl = 'https://www.monitor.cn/log/api'
}
if (host === 'www.prod.com') { // 生产域名
apiUrl = 'https://www.monitor.com/log/api'
}
function createMonitor () {
return new Monitor({
logLevel: 'info',
url: apiUrl,
commonParams: {
platformName: 'project-name',
ua: userAgent.parse(navigator.userAgent).full,
domain: document.domain,
sessionId: ''
}
})
}
const monitor = createMonitor()export function setCommonParams () {
// 获取 token
const token = someData.get('token')
if (token) {
const { sessionId } = monitor.getCommonParams()
// 只有发生改变时候才会设置
if (sessionId !== token) {
const commonParams = {
sessionId: token
}
monitor.setCommonParams(commonParams)
}
}
}
export default monitor
```- 创建 `monitorInit.js`
```js
import { injectJsError, injectXHR, blankScreen, timing, pv, longTask } from 'amazing-monitor/lib/control'
import monitor from './monitor'
injectJsError(monitor)
injectXHR(monitor)
pv(monitor)
blankScreen(monitor)
timing(monitor)
longTask(monitor)
```## 引入并使用
在 `main.js` 中引入
```js
import './monitorInit' // global monitor
```在 `router/index.js` 中全局设置
```js
import { setCommonParams } from './monitor'router.beforeEach((to, from, next) => {
// 获取 token
const token = someData.get('token')
if (token) {
setCommonParams()
}
})
```