update 推送本地文件;客户端日志采集

This commit is contained in:
gallonyin
2023-05-27 17:00:28 +08:00
parent 23b4da9294
commit 6f3ceeeb5a
8 changed files with 99 additions and 0 deletions

View File

@@ -101,6 +101,8 @@ object Constant {
fun getTestUrl() = "${getBaseUrl()}/test"
fun getPushLocalFileUrl() = "${getBaseUrl()}/fileUpload/upload?robotId=$robotId"
private fun getBaseUrl() = host.replace("wss", "https").replace("ws", "http")
}

View File

@@ -16,6 +16,7 @@ import com.umeng.commonsdk.UMConfigure
import org.yameida.worktool.config.GlobalException
import org.yameida.worktool.notification.PlayNotifyManager
import org.yameida.worktool.utils.IWWAPIUtil
import org.yameida.worktool.utils.LogUtilsInit
import update.UpdateAppUtils
class MyApplication : Application() {
@@ -40,6 +41,8 @@ class MyApplication : Application() {
super.onCreate()
//初始化工具类
Utils.init(this)
//初始化Log工具配置
LogUtilsInit.init()
GsonUtils.setGsonDelegate(Gson())
//初始化 Toast 框架
ToastUtils.init(this)

View File

@@ -58,6 +58,7 @@ public class WeworkMessageBean {
* 获取企业列表 GET_CORP_LIST
* 获取全部好友信息 GET_ALL_FRIEND_INFO
* 获取全部群信息 GET_ALL_GROUP_INFO
* 获取本地文件 GET_LOCAL_FILE
*/
public static final int HEART_BEAT = 11;
public static final int TYPE_RECEIVE_MESSAGE_LIST = 101;
@@ -109,6 +110,7 @@ public class WeworkMessageBean {
public static final int GET_CORP_LIST = 506;
public static final int GET_ALL_FRIEND_INFO = 507;
public static final int GET_ALL_GROUP_INFO = 508;
public static final int GET_LOCAL_FILE = 509;
/**
* roomType

View File

@@ -231,6 +231,9 @@ object MyLooper {
WeworkMessageBean.GET_ALL_GROUP_INFO -> {
WeworkController.getAllGroupInfo(message)
}
WeworkMessageBean.GET_LOCAL_FILE -> {
WeworkController.getLocalFile(message)
}
WeworkMessageBean.GET_CORP_LIST -> {
WeworkController.getCorpList(message)
}

View File

@@ -572,6 +572,17 @@ object WeworkController {
return WeworkGetImpl.getAllGroupInfo(message)
}
/**
* 获取本地文件
* @see WeworkMessageBean.GET_LOCAL_FILE
* @param message#fileUrl 文件地址
*/
@RequestMapping
fun getLocalFile(message: WeworkMessageBean): Boolean {
LogUtils.d("getLocalFile(): ${message.fileUrl}")
return WeworkGetImpl.getLocalFile(message, message.fileUrl)
}
/**
* 获取我的信息
* @see WeworkMessageBean.GET_MY_INFO

View File

@@ -1,5 +1,6 @@
package org.yameida.worktool.service
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SPUtils
@@ -7,6 +8,7 @@ import org.yameida.worktool.Constant
import org.yameida.worktool.model.ExecCallbackBean
import org.yameida.worktool.model.WeworkMessageBean
import org.yameida.worktool.utils.*
import java.io.File
import java.lang.StringBuilder
/**
@@ -143,6 +145,31 @@ object WeworkGetImpl {
}
}
/**
* 获取本地文件
* @see WeworkMessageBean.GET_LOCAL_FILE
* @param fileUrl 文件地址
*/
fun getLocalFile(message: WeworkMessageBean, fileUrl: String?): Boolean {
val startTime = System.currentTimeMillis()
val fileUrl = if (fileUrl.isNullOrBlank()) {
val currentLogFilePath = LogUtils.getCurrentLogFilePath()
FileUtils.copy(currentLogFilePath, "$currentLogFilePath.snapshot")
"$currentLogFilePath.snapshot"
} else fileUrl
LogUtils.d("localFileUrl: $fileUrl")
val file = File(fileUrl)
if (!file.exists()) {
LogUtils.e("文件不存在: ${file.absolutePath}")
uploadCommandResult(message, ExecCallbackBean.ERROR_TARGET, "文件不存在: ${file.absolutePath}", startTime)
return false
}
HttpUtil.pushLocalFile(file)
LogUtils.d("推送本地文件成功: ${file.absolutePath}")
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true
}
/**
* 获取我的信息
*/

View File

@@ -162,4 +162,17 @@ object HttpUtil {
}
})
}
/**
* 推送本地文件
*/
fun pushLocalFile(file: File) {
OkGo.post<String>(Constant.getPushLocalFileUrl())
.addFileParams("file", listOf(file))
.execute(object : StringCallback() {
override fun onSuccess(response: Response<String>?) {
LogUtils.d("推送本地文件成功: ${file.absolutePath}")
}
})
}
}

View File

@@ -0,0 +1,38 @@
package org.yameida.worktool.utils
import com.blankj.utilcode.util.LogUtils
object LogUtilsInit {
/**
* 参考
*
LogUtils.Config config =
LogUtils.getConfig()
.setLogSwitch(true) // 设置 log 总开关,包括输出到控制台和文件,默认开
.setConsoleSwitch(AppUtils.isAppDebug()) // 设置是否输出到控制台开关,默认开
.setGlobalTag(null) // 设置 log 全局标签,默认为空
// 当全局标签不为空时,我们输出的 log 全部为该 tag
// 为空时,如果传入的 tag 为空那就显示类名,否则显示 tag
.setLogHeadSwitch(true) // 设置 log 头信息开关,默认为开
.setLog2FileSwitch(true) // 打印 log 时是否存到文件的开关,默认关
.setDir("") // 当自定义路径为空时,写入应用的/cache/log/目录中
.setFilePrefix("LYan") // 当文件前缀为空时,默认为"util",即写入文件为"util-yyyy-MM-dd$fileExtension"
.setFileExtension(".log") // 设置日志文件后缀
.setBorderSwitch(AppUtils.isAppDebug()) // 输出日志是否带边框开关,默认开
.setSingleTagSwitch(true) // 一条日志仅输出一条,默认开,为美化 AS 3.1 的 Logcat
.setConsoleFilter(LogUtils.V) // log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
.setFileFilter(LogUtils.I) // log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
.setStackDeep(1) // log 栈深度,默认为 1
.setStackOffset(0) // 设置栈偏移,比如二次封装的话就需要设置,默认为 0
.setSaveDays(7) // 设置日志可保留天数,默认为 -1 表示无限时长
*
*/
fun init() {
LogUtils.getConfig().apply {
isLog2FileSwitch = true
saveDays = 7
}
}
}