更新记录
1.0.0(2025-11-09)
新增功能
- 新增了
自动收集应用日志、设置用户、设置标签、设置一般日志、设置警告日志、设置错误日志、设置事件日志、设置系统日志、获取日志文件列表、清理过期日志、上传日志文件、压缩并上传日志文件方法
- 初始版本
问题修复
功能优化
平台兼容性
uni-app(4.31)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| - |
- |
× |
× |
- |
- |
5.0 |
× |
× |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
| × |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
uni-app x(4.31)
| Chrome |
Safari |
Android |
Android插件版本 |
iOS |
鸿蒙 |
微信小程序 |
| × |
× |
5.0 |
1.0.0 |
× |
× |
× |
其他
闪退崩溃日志上报,设置用户信息标签,用户操作日志,主动上报日志
闪退崩溃日志上报,设置用户信息标签,用户操作日志,主动上报日志是款主动+自动收集系统日志的UTS插件,支持自动收集应用日志、设置用户、设置标签、设置一般日志、设置警告日志、设置错误日志、设置事件日志、设置系统日志、获取日志文件列表、清理过期日志、上传日志文件、压缩并上传日志文件
需要权限
"android.permission.READ_EXTERNAL_STORAGE"
"android.permission.WRITE_EXTERNAL_STORAGE"
- 即:在
manifest.json中的distribute.android.permissions加入
// 读取文件时需要
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
// 写入文件时需要(默认保存到沙盒缓存)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
使用示例【此示例只实现了设置日志的逻辑】
<template>
<view class="content">
<!-- App -->
<view class="content-title">设置日志</view>
<view class="content-message">(App组件描述)</view>
<view class="content-button ima-log" @click="logInfoClick">设置一般日志</view>
<view class="content-button ima-log" @click="logWarnClick">设置警告日志</view>
<view class="content-button ima-log" @click="logErrorClick">设置错误日志</view>
<view class="content-button ima-log" @click="logUserClick">设置事件日志【自定义】</view>
<view class="content-button ima-log" @click="logAppClick">设置系统日志【自定义】</view>
</view>
</template>
<script lang="ts">
import {
// 方法
initLog,
setUser,
setTag,
logInfo,
logWarn,
logError,
logUser,
logApp
} from '@/uni_modules/ima-log'
export default {
data() {
return {
}
},
onLoad() {
// 开启自动接听
initLog()
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
},
methods: {
// 设置用户
setUserClick() {
setUser('码小趣')
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
},
// 设置标签
setTagClick() {
setTag('标签')
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
},
// 设置一般日志
logInfoClick() {
logInfo('一般日志')
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
},
// 设置警告日志
logWarnClick() {
logWarn('警告日志')
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
},
// 设置错误日志
logErrorClick() {
logError('错误日志')
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
},
// 设置事件日志【自定义】
logUserClick() {
logUser('设置事件日志', 'logUser')
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
},
// 设置系统日志【自定义】
logAppClick() {
logApp('设置系统日志', 'logApp')
.then((res: any) => {
console.log(res)
})
.catch((err: any) => {
console.log(err)
})
}
}
}
</script>
<style lang="scss">
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
&-title {
margin-top: 10rpx;
padding: 10rpx;
font-size: 44rpx;
font-weight: 800;
color: #ff0000;
}
&-message {
font-size: 28rpx;
font-weight: 800;
text-align: center;
color: #ff6700;
}
&-button {
height: 65rpx;
width: 750rpx;
padding: 20rpx;
line-height: 65rpx;
text-align: center;
background: #00e0f1;
margin-bottom: 25rpx;
}
}
</style>
方法
| 方法名称 |
说明 |
方法参数 |
平台 |
| initLog |
初始化自动收集应用日志 |
无 |
android |
| setUser(userId,userName) |
设置用户 |
userId: 设置的用户id,userName:设置的用户名称【可不传】 |
android |
| setTag(tag) |
设置标签 |
tag:设置的标签名称 |
android |
| logInfo(msg) |
设置一般日志 |
msg:日志内容 |
android |
| logWarn(msg) |
设置警告日志 |
msg:日志内容 |
android |
| logError(msg) |
设置错误日志 |
msg:日志内容 |
android |
| logUser(msg,type) |
设置用户自定义事件日志 |
msg:日志内容,type:用户自定义标识【可不传】 |
android |
| logApp(msg,type) |
设置用户自定义系统日志 |
msg:日志内容,type:用户自定义标识【可不传】 |
android |
| getLogFiles(include) |
获取日志文件列表 |
include:是否包含系统日志文件 log_apps.log 【默认: false】 |
android |
| cleanLogs(keepDay) |
清理过期日志(保留最近 n 天) |
keepDay:保留最近 n 天的日志,不清理 log_apps.log【默认: 30】 |
android |
| uploadLog(options,callback) |
上传日志文件 |
options:参考 IUpload,onCallback(result : IReturn) => void |
android |
| uploadZip(options,callback) |
压缩并上传日志文件 |
options:参考 IUpload,onCallback(result : IReturn) => void |
android |
IUpload 上传参数
type IUpload = {
serverUrl : string // 上传接口【必传】
headers ?: UTSJSONObject | null // 请求头参数
parameters ?: UTSJSONObject | null // 附加的表单参数
timeout ?: number // 接口超时时间
include ?: boolean // 是否包含系统日志`log_apps.log`
days ?: number // 上传近几天的日志
}