trace-log-utils
v1.0.11
Published
埋点上报工具
Readme
日志上报埋点工具
npm i trace-log-utils| reportFunction | debounceTime | maxReportLength | | :----------------:| :----------------:| :----------------:| | 上报数据处理函数 | 自动上报间隔时间 | 一次性上报条数上限 | | 必传 | 非必传 | 非必传 | | 无默认 | 默认 30S | 默认 1000 条 |
import Tracker from 'trace-log-utils'
const tracker = new Tracker({ reportFunction: (data: any[]) => Promise<void>; debounceTime?: number; maxReportLength?: number })
const reportFunction = (reportList) => {
return new Promise(async (resolve, reject) => {
try {
<!-- 在这里处理自己想要上传的数据格式 -->
await fetch(this.reportUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(reportList),
})
resolve()
} catch(err){
reject(err)
}
})
}- trackReport(details: object)
上报一条数据
const report = {
code: "xxxxx",
source: "xxxx",
base_info: "This is some additional information."
}
tracker.trackReport(report)- trackReportNow(details: object)
立即上报一条数据
const report = {
code: "xxxxx",
source: "xxxx",
base_info: "This is some additional information."
}
tracker.trackReportNow(report)