Commit de7c6ccf by yixinjj

新增日志管理

1 parent 9139685f
...@@ -39,8 +39,10 @@ ...@@ -39,8 +39,10 @@
.icon-mask-del { width: 80rpx; height: 80rpx; background-position: -95rpx -964rpx;} .icon-mask-del { width: 80rpx; height: 80rpx; background-position: -95rpx -964rpx;}
.icon-mask-edit { width: 80rpx; height: 80rpx; background-position: -190rpx -964rpx;} .icon-mask-edit { width: 80rpx; height: 80rpx; background-position: -190rpx -964rpx;}
.icon-no-insurance-data { width: 488rpx; height: 296rpx; background-position: 0rpx -415rpx;} .icon-no-insurance-data { width: 488rpx; height: 296rpx; background-position: 0rpx -415rpx;}
.icon-pause { width: 40rpx; height: 40rpx; background-position: -940rpx -668rpx;}
.icon-pen-active { width: 120rpx; height: 120rpx; background-position: -646rpx -415rpx;} .icon-pen-active { width: 120rpx; height: 120rpx; background-position: -646rpx -415rpx;}
.icon-pen { width: 120rpx; height: 120rpx; background-position: -503rpx -558rpx;} .icon-pen { width: 120rpx; height: 120rpx; background-position: -503rpx -558rpx;}
.icon-play { width: 40rpx; height: 40rpx; background-position: -995rpx -668rpx;}
.icon-qr-success { width: 96rpx; height: 96rpx; background-position: -1190rpx -726rpx;} .icon-qr-success { width: 96rpx; height: 96rpx; background-position: -1190rpx -726rpx;}
.icon-qw { width: 48rpx; height: 48rpx; background-position: -765rpx -558rpx;} .icon-qw { width: 48rpx; height: 48rpx; background-position: -765rpx -558rpx;}
.icon-record-active { width: 112rpx; height: 112rpx; background-position: -381rpx -726rpx;} .icon-record-active { width: 112rpx; height: 112rpx; background-position: -381rpx -726rpx;}
...@@ -48,7 +50,7 @@ ...@@ -48,7 +50,7 @@
.icon-scan { width: 32rpx; height: 32rpx; background-position: -617rpx -853rpx;} .icon-scan { width: 32rpx; height: 32rpx; background-position: -617rpx -853rpx;}
.icon-scene-0 { width: 96rpx; height: 96rpx; background-position: 0rpx -853rpx;} .icon-scene-0 { width: 96rpx; height: 96rpx; background-position: 0rpx -853rpx;}
.icon-scene-1 { width: 96rpx; height: 96rpx; background-position: -111rpx -853rpx;} .icon-scene-1 { width: 96rpx; height: 96rpx; background-position: -111rpx -853rpx;}
.icon-search { width: 40rpx; height: 40rpx; background-position: -940rpx -668rpx;} .icon-search { width: 40rpx; height: 40rpx; background-position: -1050rpx -668rpx;}
.icon-second-nav { width: 480rpx; height: 176rpx; background-position: -830rpx 0rpx;} .icon-second-nav { width: 480rpx; height: 176rpx; background-position: -830rpx 0rpx;}
.icon-setting { width: 64rpx; height: 64rpx; background-position: -372rpx -964rpx;} .icon-setting { width: 64rpx; height: 64rpx; background-position: -372rpx -964rpx;}
.icon-store { width: 96rpx; height: 96rpx; background-position: -222rpx -853rpx;} .icon-store { width: 96rpx; height: 96rpx; background-position: -222rpx -853rpx;}
...@@ -57,6 +59,4 @@ ...@@ -57,6 +59,4 @@
.icon-tool-finish { width: 60rpx; height: 60rpx; background-position: -526rpx -964rpx;} .icon-tool-finish { width: 60rpx; height: 60rpx; background-position: -526rpx -964rpx;}
.icon-tool-pay { width: 60rpx; height: 60rpx; background-position: -601rpx -964rpx;} .icon-tool-pay { width: 60rpx; height: 60rpx; background-position: -601rpx -964rpx;}
.icon-total { width: 32rpx; height: 32rpx; background-position: -664rpx -853rpx;} .icon-total { width: 32rpx; height: 32rpx; background-position: -664rpx -853rpx;}
.icon-visible { width: 40rpx; height: 40rpx; background-position: -995rpx -668rpx;}
.icon-play { width: 40rpx; height: 40rpx; background-position: -1050rpx -668rpx;}
.icon-pause { width: 40rpx; height: 40rpx; background-position: -1105rpx -668rpx;}
\ No newline at end of file \ No newline at end of file
.icon-visible { width: 40rpx; height: 40rpx; background-position: -1105rpx -668rpx;}
\ No newline at end of file \ No newline at end of file

1.19 MB | W: | H:

1.19 MB | W: | H:

assets/images/sprite.png
assets/images/sprite.png
assets/images/sprite.png
assets/images/sprite.png
  • 2-up
  • Swipe
  • Onion skin
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
</head>
<style>
body,
html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
background: rgb(0, 0, 0, 0.5);
}
.loading { <head>
width: 50px; <meta charset="utf-8" />
height: 50px; <meta name="viewport" content="width=device-width, initial-scale=1" />
border: 3px solid #666; <title></title>
border-radius: 50%; </head>
border-top-color: #fff; <style>
animation: spin 1s linear infinite; body,
html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
background: rgb(0, 0, 0, 0.5);
}
.loading {
width: 50px;
height: 50px;
border: 3px solid #666;
border-radius: 50%;
border-top-color: #fff;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
} }
@keyframes spin { 100% {
0% { transform: rotate(360deg);
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
} }
</style> }
</style>
</head> </head>
<body> <body>
<div class="loading"></div> <div class="loading"></div>
<script src="js/uni.webview.1.5.5.js"></script> <script src="js/uni.webview.1.5.5.js"></script>
<script src="js/aliyun-oss-sdk-6.18.1.min.js"></script> <script src="js/aliyun-oss-sdk-6.18.1.min.js"></script>
<script src="js/OSSUpLoader.js"></script> <script src="js/OSSUpLoader.js"></script>
<script> <script>
// document.addEventListener('UniAppJSBridgeReady', function(){ // document.addEventListener('UniAppJSBridgeReady', function(){
/** /**
* 该函数用于接收来自 UniApp 的消息,它包含了文件上传所需的所有信息 * 该函数用于接收来自 UniApp 的消息,它包含了文件上传所需的所有信息
* @param {string} accessKeyId - OSS 访问密钥 ID * @param {string} accessKeyId - OSS 访问密钥 ID
* @param {string} accessKeySecret - OSS 访问密钥 secret * @param {string} accessKeySecret - OSS 访问密钥 secret
* @param {string} stsToken - 安全令牌服务(STS)令牌,用于临时访问 OSS 存储桶 * @param {string} stsToken - 安全令牌服务(STS)令牌,用于临时访问 OSS 存储桶
* @param {string} fileName - 要上传的文件名 * @param {string} fileName - 要上传的文件名
* @param {string} filePath - 要上传的文件所在路径 * @param {string} filePath - 要上传的文件所在路径
* @param {Object} options - (可选)包含上传器配置的对象,如 region * @param {string} recordId - 与上传文件相关联的记录ID
* @throws {Error} 如果缺少必要的参数,将抛出错误 * @param {Object} options - (可选)包含上传器配置的对象,如 region
*/ * @throws {Error} 如果缺少必要的参数,将抛出错误
window.msgFromUniapp = function ( */
accessKeyId, window.msgFromUniapp = function (accessKeyId, accessKeySecret, stsToken, fileName, filePath, recordId, options = {}) {
accessKeySecret, console.log(fileName, filePath)
stsToken, if (!accessKeyId || !accessKeySecret || !stsToken || !fileName || !filePath) {
throw new Error('accessKeyId,accessKeySecret,stsToken,fileName,filePath is required')
}
try {
// 使用 Object.assign 合并默认配置参数和传入的 options 参数
const opt = Object.assign({ accessKeyId, accessKeySecret, stsToken, filePath, recordId }, options)
// 创建 OSSUpLoader 实例,传入配置对象
let uploader = new OSSUpLoader(opt)
// 调用 upload 方法上传文件,并在完成后处理结果
uploader.upload(fileName, function (result) {
// 通过 uni.postMessage 将上传结果作为数据发送
uni.postMessage({
data: {
...result,
fileName,
recordId,
filePath
}
})
// 调用 destroy 方法,这将重置上传器的状态,释放资源
uploader.destroy()
// 将 uploader 置为 null,释放内存
uploader = null
})
} catch (e) {
// 如果发生错误,将错误信息作为数据发送
uni.postMessage({
data: {
code: 1,
fileName, fileName,
filePath,
recordId, recordId,
options = {} filePath,
) { error: e.message
console.log(fileName, filePath); }
if ( })
!accessKeyId || }
!accessKeySecret || }
!stsToken || // }, false);
!fileName || </script>
!filePath </body>
) {
throw new Error( </html>
"accessKeyId,accessKeySecret,stsToken,fileName,filePath is required"
);
}
try {
// 使用 Object.assign 合并默认配置参数和传入的 options 参数
const opt = Object.assign(
{ accessKeyId, accessKeySecret, stsToken, filePath, recordId },
options
);
// 创建 OSSUpLoader 实例,传入配置对象
let uploader = new OSSUpLoader(opt);
// 调用 upload 方法上传文件,并在完成后处理结果
uploader.upload(fileName, function (result) {
// 通过 uni.postMessage 将上传结果作为数据发送
uni.postMessage({
data: {
...result,
fileName,
recordId,
filePath,
},
});
// 调用 destroy 方法,这将重置上传器的状态,释放资源
uploader.destroy();
// 将 uploader 置为 null,释放内存
uploader = null;
});
} catch (e) {
// 如果发生错误,将错误信息作为数据发送
uni.postMessage({
data: {
code: 1,
fileName,
recordId,
filePath,
error: e.message,
},
});
}
};
// }, false);
</script>
</body>
</html>
\ No newline at end of file \ No newline at end of file
/* /*
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-07 17:09:53 * @Date: 2024-04-07 17:09:53
* @LastEditors: 前端 qianduan01@didihu.com.cn * @LastEditors: limin
* @LastEditTime: 2024-04-11 16:47:29 * @LastEditTime: 2024-09-03 19:12:36
* @FilePath: \gl_tape\main.js * @FilePath: \gl_tape\main.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
...@@ -18,6 +18,7 @@ import wnCanvas from "./components/Canvas/wn-canvas"; ...@@ -18,6 +18,7 @@ import wnCanvas from "./components/Canvas/wn-canvas";
import UpdateBox from "./components/UpdateBox"; import UpdateBox from "./components/UpdateBox";
import webView from "./components/WebView"; import webView from "./components/WebView";
import utils from "./utils/utils"; import utils from "./utils/utils";
import logger from "./utils/logger";
Vue.use(webView); Vue.use(webView);
Vue.component("GlsxImage", GlsxImage); Vue.component("GlsxImage", GlsxImage);
Vue.component("MessageBox", MessageBox); Vue.component("MessageBox", MessageBox);
...@@ -32,11 +33,12 @@ uni.$lock = false; ...@@ -32,11 +33,12 @@ uni.$lock = false;
uni.$storage = new Storage(); uni.$storage = new Storage();
uni.$throttle = utils.throttle; uni.$throttle = utils.throttle;
uni.$isNetWork = utils.isNetWork; uni.$isNetWork = utils.isNetWork;
uni.$logger = logger;
Vue.config.productionTip = false; Vue.config.productionTip = false;
App.mpType = "app"; App.mpType = "app";
Vue.prototype.$ossDomain = config.OSS_DOMAIN; Vue.prototype.$ossDomain = config.OSS_DOMAIN;
import permision from "@/js_sdk/wa-permission/permission.js"; import permision from "@/js_sdk/wa-permission/permission.js";
import { index } from "./env"; // import { index } from "./env";
// switch (uni.getSystemInfoSync().platform) { // switch (uni.getSystemInfoSync().platform) {
// case "android": // case "android":
// permision.requestAndroidPermission("android.permission.RECORD_AUDIO"); // permision.requestAndroidPermission("android.permission.RECORD_AUDIO");
...@@ -48,15 +50,16 @@ import { index } from "./env"; ...@@ -48,15 +50,16 @@ import { index } from "./env";
// break; // break;
// } // }
Vue.prototype.$permision = permision; Vue.prototype.$permision = permision;
import sentryInit from "@/utils/sentryConfig/sentryInit";
if (index == 3) { // import sentryInit from "@/utils/sentryConfig/sentryInit";
const sentry = sentryInit(); // if (index == 3) {
Vue.prototype.$sendSentry = function (e) { // const sentry = sentryInit();
sentry.captureException(e); // Vue.prototype.$sendSentry = function (e) {
}; // sentry.captureException(e);
} else { // };
Vue.prototype.$sendSentry = function () {}; // } else {
} // Vue.prototype.$sendSentry = function () {};
// }
const app = new Vue({ const app = new Vue({
store, store,
......
...@@ -26,6 +26,7 @@ export default { ...@@ -26,6 +26,7 @@ export default {
this.wv = await this.initWebview() this.wv = await this.initWebview()
await this.enQueue() await this.enQueue()
this.polling() this.polling()
// uni.$logger.error({ extra : { key: 'data', value: {'abc':123,'sss':456,'GDF':888} }, msg:'test', tag : { key: 'test', value: 'test' } })
}, },
/** /**
* 处理消息函数 * 处理消息函数
...@@ -98,6 +99,7 @@ export default { ...@@ -98,6 +99,7 @@ export default {
* @throws {Error} 如果获取快照失败或扁平化数据失败,将抛出错误 * @throws {Error} 如果获取快照失败或扁平化数据失败,将抛出错误
*/ */
async enQueue() { async enQueue() {
// uni.$logger.remote.error({ extra : { key: 'data', value: {test:'test'} }, msg:'test', tag : { key: 'test', value: 'test' } })
const _snapshot = await this.getRecordsSnapshotFlatten() const _snapshot = await this.getRecordsSnapshotFlatten()
this.snapshot = new Queue(_snapshot) this.snapshot = new Queue(_snapshot)
console.log('创建任务快照.下一轮快照文件个数:', this.snapshot.size) console.log('创建任务快照.下一轮快照文件个数:', this.snapshot.size)
......
import LogCat from './LogCat'
import { LogLevel } from './constants'
class LocalLog {
logger = null
constructor() {
this.logger = LogCat
this.logger.init()
}
debug(msg) {
this.logger.writeLog(LogLevel.DEBUG, msg)
}
info(msg) {
this.logger.writeLog(LogLevel.INFO, msg)
}
warn(msg) {
this.logger.writeLog(LogLevel.WARN, msg)
}
error(msg) {
this.logger.writeLog(LogLevel.ERROR, msg)
}
}
export default LocalLog
import { getTime } from './util'
const LogCat = {
main: plus.android.runtimeMainActivity(),
Environment: plus.android.importClass('android.os.Environment'),
BufferedWriter: plus.android.importClass('java.io.BufferedWriter'),
BufferedReader: plus.android.importClass('java.io.BufferedReader'),
File: plus.android.importClass('java.io.File'),
FileOutputStream: plus.android.importClass('java.io.FileOutputStream'),
FileInputStream: plus.android.importClass('java.io.FileInputStream'),
OutputStreamWriter: plus.android.importClass('java.io.OutputStreamWriter'),
InputStreamReader: plus.android.importClass('java.io.InputStreamReader'),
LogPath: '',
init: function (folderName = '_zyzs_log') {
if (this.Environment.MEDIA_MOUNTED || !this.Environment.isExternalStorageRemovable()) {
this.LogPath = this.main.getExternalFilesDir(null).getPath() + folderName
} else {
this.LogPath = this.main.getFilesDir().getPath() + folderName
}
console.log('日志文件存放路径->', this.LogPath)
},
writeLog: function (tag, msg) {
let date = getTime('YYYY-MM-DD')
let datetime = getTime()
msg = typeof msg !== 'string' ? JSON.stringify(msg) : msg
//文件名
let fileName = this.LogPath + date + '.txt'
//写入的内容
let content = `${datetime} ${tag}:${msg}\n`
let file = new this.File(this.LogPath)
if (!file.exists()) {
file.mkdirs() //创建父路径
}
let fos = null
let bw = null
try {
fos = new this.FileOutputStream(fileName, true)
bw = new this.BufferedWriter(new this.OutputStreamWriter(fos))
//bw.write(log);
bw.append(content)
} catch (e) {
console.log('e->', e)
} finally {
try {
if (bw != null) {
bw.close() //关闭缓冲流
fos.close() //关闭文件输出流
}
} catch (closeEx) {
console.log('closeEx->', closeEx)
}
}
},
// 删除日志
removeLogFile: function (fileName) {
let file = new this.File(fileName)
let fos = new this.FileOutputStream(fileName, true)
fos.close()
file.delete()
console.log('删除------' + fileName)
},
// 获取所有日志文件列表
getLogFileList: function () {
let list = []
let file = new this.File(this.LogPath)
let tempList = file.listFiles()
for (let i = 0; i < tempList.length; i++) {
let fileName = tempList[i].getName()
let filePath = tempList[i].getPath()
let obj = {
name: fileName,
filePath: filePath
}
list.push(obj)
}
return list
},
// 读取日志具体内容
readLog: function (path) {
// 编码格式
const charset = 'utf-8'
let file = new this.File(path)
let inputStreamReader = null
let bufferedReader = null
let list = []
try {
//不存在
if (!file.exists()) {
return list
}
inputStreamReader = new this.InputStreamReader(new this.FileInputStream(file), charset)
bufferedReader = new this.BufferedReader(inputStreamReader)
let line = ''
while (null != (line = bufferedReader.readLine())) {
if (line) {
list.push(line)
}
}
bufferedReader.close()
inputStreamReader.close()
} catch (e) {
console.error(e)
if (bufferedReader) {
bufferedReader.close()
}
if (inputStreamReader) {
inputStreamReader.close()
}
return list
}
return list
}
}
export default LogCat
import sentryInit from '@/utils/sentryConfig/sentryInit'
import { LogLevel } from './constants'
class RemoteLog {
sentry = null
constructor(user) {
this.sentry = sentryInit()
this.sentry.setUser(user)
}
debug(info) {
this.send(LogLevel.DEBUG, info)
}
info(info) {
this.send(LogLevel.INFO, info)
}
warn(info) {
this.send(LogLevel.WARN, info)
}
error(info) {
this.send(LogLevel.ERROR, info)
}
send(level, { extra = { key: 'data', value: {} }, msg, tag = { key: '', value: '' } }) {
this.sentry.withScope(scope => {
scope.setTag(tag.key, tag.value)
scope.setExtra(extra.key, extra.value)
scope.setLevel(level)
this.sentry.captureException(msg)
})
}
}
export default RemoteLog
const LogLevel = {
DEBUG: 'debug',
INFO: 'info',
WARN: 'warn',
ERROR: 'error'
}
export { LogLevel }
// import { index } from './env'
import RemoteLog from './RemoteLog'
import LocalLog from './LocalLog'
import { LogLevel } from './constants'
import { storageApi } from '../cache'
import { getIp } from './util'
class Logger {
remote = null
local = null
fields = []
constructor(fields = []) {
this.fields = fields
this.init()
}
async init() {
const user = await this.getUserInfo()
this.remote = new RemoteLog(user)
this.local = new LocalLog()
}
debug(info) {
this.white(LogLevel.DEBUG, info)
}
info(info) {
this.white(LogLevel.INFO, info)
}
warn(info) {
this.white(LogLevel.WARN, info)
}
error(info) {
this.white(LogLevel.ERROR, info)
}
white(level, info) {
this.remote[level](info)
this.local[level](JSON.stringify(info))
}
async getUserInfo() {
const userInfo = storageApi.getUserInfo()
const ip = await getIp()
const user = this.fields.reduce((pre, cur) => {
pre[cur] = userInfo[cur]
return pre
}, {})
user.name = userInfo.name
user.ip = ip
return user
}
}
export default new Logger()
/**
*获取各种时间格式
* @style 1. hh:mm:ss 时:分:秒
* 2.YYYY-MM-DD 年-月-日
* 3.YYYYMMDD 年月日
* 4.YYYY-MM-DD hh:mm:ss 年-月-日 时:分:秒
* 5.YYYYMMDDhhmmss 年月日时分秒
* 6.DD 日
* 7.getDay 获取当前星期几
* 8.hhmmss 时分秒
* */
const getTime = style => {
let time = new Date()
let times = ''
//获取年月日
let yyyy = time.getFullYear()
let mm = time.getMonth()
mm = mm >= 9 ? mm + 1 : '0' + (mm + 1)
let dd = time.getDate()
dd = dd >= 10 ? dd : '0' + dd
//获取时分秒
let h = time.getHours()
h = h >= 10 ? h : '0' + h
let m = time.getMinutes()
m = m >= 10 ? m : '0' + m
let s = time.getSeconds()
s = s >= 10 ? s : '0' + s
// 获取星期
let z = time.getDay()
z = '0' + z
if (style === 'YYYY-MM-DD') {
times = yyyy + '-' + mm + '-' + dd
}
if (style === 'hh:mm:ss') {
times = h + ':' + m + ':' + s
}
if (style === 'YYYYMMDD') {
times = yyyy + '' + mm + '' + dd
}
if (style === 'YYYY') {
times = yyyy + ''
}
if (style === 'MM') {
times = mm + ''
}
if (style === 'DD') {
times = dd + ''
}
if (style === 'YYYY-MM-DD hh:mm:ss' || !style) {
times = yyyy + '-' + mm + '-' + dd + ' ' + h + ':' + m + ':' + s
}
if (style === 'YYYYMMDDhhmmss') {
times = yyyy + '' + mm + '' + dd + '' + h + '' + m + '' + s
}
if (style === 'DD') {
times = dd + ''
}
if (style === 'getDay') {
times = z + ''
}
return times
}
const getIp = () => {
return new Promise((resolve, reject) => {
uni.request({
url: 'https://api.ipify.org', // 这是一个提供获取客户端公网IP服务的简单API
method: 'GET',
success: res => {
const ip = res.data
resolve(ip)
},
fail: err => {
reject(err)
}
})
})
}
export { getTime, getIp }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!