Package Exports
- wind-logger-miniprogram
- wind-logger-miniprogram/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wind-logger-miniprogram) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
wind-logger-miniprogram
风行前端行为日志收集模块-微信小程序
安装
// 1. 在小程序开发工具
npm install wind-logger-miniprogram --save
// 2. 小程序开发工具选择 [工具] -> [构建npm]
不错的教程👇🏻👇🏻👇🏻
引入日志模块
import FxLogger from 'wind-logger-miniprogram'
const LOGGER_CONFIG = {
app: 'logger-test',
remote: 'http://action.fxscm.net/logger/v1/shopedi/loggers',
defaultInfo: {
appType: 'logger-demo-miniprogram'
},
customInfo: {
actionType: ''
}
}
// 创建日志实例
const $fxLogger = new FxLogger(LOGGER_CONFIG)
App({
onLaunch() {
// 挂载日志模块
this.globalData.$fxLogger = $fxLogger
},
globalData: {},
onError (error) {
// 捕获error日志
$fxLogger.runtimeInfo(error)
}
})
使用方法
// 日志初始化
app.globalData.$fxLogger.init({
username: '系统管理员',
userId: '1'
})
// 切换用户
app.globalData.$fxLogger.setUserInfo({
username: '用户01',
userId: '2'
})
// 发送成功日志
const logger = app.globalData.$fxLogger.actionInfo({
message: '成功的日志消息1',
// 公司定义的默认日志字段
oneStageModule: '一级菜单1',
twoStageModule: '二级菜单1',
// 生产线定义的自定义日志字段
actionType: 'demo按钮2'
})
setTimeout(() => {
logger.success()
}, 1000)
// 发送失败的日志
const logger = app.globalData.$fxLogger.actionInfo({
message: '失败的日志消息'
})
setTimeout(() => {
logger.error('服务器异常')
}, 1000)
// 对request请求进行捕获
fxRequest ({ url, data, query }) {
return new Promise((resolve, reject) => {
// 创建request日志
const logger = app.globalData.$fxLogger.requestInfoStart({ url, data, query })
setTimeout(() => {
if (data.billType === '1') {
const succesResponse = {
result: true
}
// 成功日志的手收集
logger.end({
res: succesResponse
})
resolve(succesResponse)
} else {
const errorResponse = {
result: false,
message: '单据类型错误'
}
// 失败日志的收集
logger.end({
error: errorResponse
})
reject(errorResponse)
}
}, 1000)
})
}