Commit 7f914200 by 张立顺

回退 日志文件

1 parent a0e33327
{
"name": "gl-tape",
"name": "gl_tape",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "gl_tape",
"dependencies": {
"dayjs": "^1.11.11",
"eslint-config-prettier": "^9.1.0",
......@@ -998,9 +999,9 @@
}
},
"node_modules/semver": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.0.3.tgz",
"integrity": "sha512-5OkOBiw69xqmxOFIXwXsiY1HlE+om8nNptg1ZIf95fzcnfgOv2fLm7pmmGbRJsjJIqPpW5Kwy4wpDBTz5wQlUw==",
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
"integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==",
"bin": {
"semver": "bin/semver"
}
......@@ -1034,14 +1035,14 @@
}
},
"node_modules/spritesmith": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/spritesmith/-/spritesmith-3.4.1.tgz",
"integrity": "sha512-NQZ8c7bZKbtqc0n0V+vVpurV72BwziOXw8AAU/nOdrjcjgCVoy+XUoopbrAYaNfJJgK730U98SB579+YtzfUJw==",
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/spritesmith/-/spritesmith-3.5.1.tgz",
"integrity": "sha512-FrzGx9cD5SkH3Kxuk24vJJLBYHLyDskUJ2t6DSWfWkCd8+yFQAfBGVE7F0IhOpKu+aq1CZ9rgXnpaa4luIQgGg==",
"dependencies": {
"concat-stream": "~1.5.1",
"layout": "~2.2.0",
"pixelsmith": "^2.3.0",
"semver": "~5.0.3",
"semver": "~5.7.2",
"through2": "~2.0.0"
},
"engines": {
......
import { getTime } from './util'
import { serializeIfObject } from '../utils'
class LogCat {
// main = plus.android.runtimeMainActivity()
// File = plus.android.importClass('java.io.File')
// Environment = plus.android.importClass('android.os.Environment')
// BufferedWriter = plus.android.importClass('java.io.BufferedWriter')
// FileOutputStream = plus.android.importClass('java.io.FileOutputStream')
// OutputStreamWriter = plus.android.importClass('java.io.OutputStreamWriter')
main = plus.android.runtimeMainActivity()
File = plus.android.importClass('java.io.File')
Environment = plus.android.importClass('android.os.Environment')
BufferedWriter = plus.android.importClass('java.io.BufferedWriter')
FileOutputStream = plus.android.importClass('java.io.FileOutputStream')
OutputStreamWriter = plus.android.importClass('java.io.OutputStreamWriter')
// BufferedReader = plus.android.importClass('java.io.BufferedReader')
// FileInputStream = plus.android.importClass('java.io.FileInputStream')
// InputStreamReader = plus.android.importClass('java.io.InputStreamReader')
LogPath = ''
constructor(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)
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(tag, messages) {
return
let msg = serializeIfObject(messages)
let date = getTime('YYYY-MM-DD')
let datetime = getTime()
......@@ -36,7 +33,7 @@ class LogCat {
path.mkdirs() //创建父路径
}
let fos = null
let bw = null
let bw = null
try {
fos = new this.FileOutputStream(fileName, true)
bw = new this.BufferedWriter(new this.OutputStreamWriter(fos))
......@@ -78,3 +75,83 @@ class LogCat {
}
}
export default LogCat
// import { getTime } from './util'
// import { serializeIfObject } from '../utils'
// class LogCat {
// // main = plus.android.runtimeMainActivity()
// // File = plus.android.importClass('java.io.File')
// // Environment = plus.android.importClass('android.os.Environment')
// // BufferedWriter = plus.android.importClass('java.io.BufferedWriter')
// // FileOutputStream = plus.android.importClass('java.io.FileOutputStream')
// // OutputStreamWriter = plus.android.importClass('java.io.OutputStreamWriter')
// // BufferedReader = plus.android.importClass('java.io.BufferedReader')
// // FileInputStream = plus.android.importClass('java.io.FileInputStream')
// // InputStreamReader = plus.android.importClass('java.io.InputStreamReader')
// LogPath = ''
// constructor(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(tag, messages) {
// return
// let msg = serializeIfObject(messages)
// let date = getTime('YYYY-MM-DD')
// let datetime = getTime()
// //文件名
// let fileName = this.LogPath + '/' + date + '.txt'
// //写入的内容
// let content = `${datetime} [${tag}] : ${msg}\n`
// console.log(content.replace(/\n/g, ''))
// let path = new this.File(this.LogPath)
// if (!path.exists()) {
// path.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(fileName) {
// let file = new this.File(fileName)
// let fos = new this.FileOutputStream(fileName, true)
// fos.close()
// file.delete()
// console.log('删除------' + fileName)
// }
// // 获取所有日志文件列表
// getLogFileList() {
// let file = new this.File(this.LogPath)
// let tempList = file.listFiles()
// if (!tempList || tempList.length === 0) return []
// const list = tempList.map(file => {
// return {
// name: file.getName(),
// path: file.getPath()
// }
// })
// return list
// }
// }
// export default LogCat
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!