|
|
@@ -6,6 +6,7 @@ import android.content.Context
|
|
|
import android.content.pm.ActivityInfo
|
|
|
import android.os.Bundle
|
|
|
import android.text.TextUtils
|
|
|
+import android.util.Log
|
|
|
import android.view.KeyEvent
|
|
|
import android.view.ViewGroup
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
@@ -15,6 +16,10 @@ import androidx.appcompat.app.AppCompatActivity
|
|
|
import androidx.databinding.ViewDataBinding
|
|
|
import androidx.fragment.app.Fragment
|
|
|
import com.alibaba.android.arouter.launcher.ARouter
|
|
|
+import com.aliyun.sls.android.producer.LogProducerCallback
|
|
|
+import com.aliyun.sls.android.producer.LogProducerClient
|
|
|
+import com.aliyun.sls.android.producer.LogProducerConfig
|
|
|
+import com.aliyun.sls.android.producer.LogProducerException
|
|
|
import com.scwang.smartrefresh.layout.api.RefreshLayout
|
|
|
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener
|
|
|
import com.yingyangfly.baselib.R
|
|
|
@@ -28,6 +33,7 @@ import com.yingyangfly.baselib.dialog.LoadingDialog
|
|
|
import com.yingyangfly.baselib.dialog.TaskFragment
|
|
|
import com.yingyangfly.baselib.ext.getDbClass
|
|
|
import com.yingyangfly.baselib.ext.initBar
|
|
|
+import com.yingyangfly.baselib.ext.loge
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
import com.yingyangfly.baselib.utils.*
|
|
|
import gorden.rxbus2.RxBus
|
|
|
@@ -35,8 +41,7 @@ import gorden.rxbus2.RxBus
|
|
|
/**
|
|
|
* activity基类
|
|
|
*/
|
|
|
-abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(),
|
|
|
- OnRefreshLoadMoreListener {
|
|
|
+abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(), OnRefreshLoadMoreListener {
|
|
|
|
|
|
/**
|
|
|
* 确定初始化将总是发生在单个线程,那么你可以使用 LazyThreadSafetyMode.NONE模式, 它不会有任何线程安全的保证和相关的开销。
|
|
|
@@ -66,6 +71,8 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(),
|
|
|
|
|
|
private var logoutDialog: AlertDialog? = null
|
|
|
|
|
|
+ private var client: LogProducerClient? = null
|
|
|
+
|
|
|
var db: AppDataBase? = null
|
|
|
|
|
|
/**
|
|
|
@@ -96,8 +103,7 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(),
|
|
|
ActivityManagers.instance.addActivity(this)
|
|
|
initSmartRefresh()
|
|
|
val params: ViewGroup.LayoutParams = LinearLayout.LayoutParams(
|
|
|
- LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
- LinearLayout.LayoutParams.MATCH_PARENT, 1.0f
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f
|
|
|
)
|
|
|
binding.root.layoutParams = params
|
|
|
bindingBase.llytContent.addView(binding.root)
|
|
|
@@ -108,6 +114,7 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(),
|
|
|
doctorDao = db?.getDoctorsDao()
|
|
|
gameSoundDao = db?.getGameSoundDao()
|
|
|
}
|
|
|
+ initProducer()
|
|
|
initMVVM()
|
|
|
initViews()
|
|
|
initListener()
|
|
|
@@ -115,6 +122,94 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(),
|
|
|
initLiveEventBusUtil()
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化阿里云日志上报
|
|
|
+ */
|
|
|
+ private fun initProducer() {
|
|
|
+ Log.e("wpp", "初始化阿里云")
|
|
|
+ try {
|
|
|
+ val config = LogProducerConfig(
|
|
|
+ this,
|
|
|
+ "https://cn-beijing.log.aliyuncs.com",
|
|
|
+ "hcp-pad",
|
|
|
+ "hcp-pad",
|
|
|
+ "LTAI5tRoqTKsfW84PZfN1PtD",
|
|
|
+ "CvzYhzJUnN9YsAd7zuv031bx2l8pj5",
|
|
|
+ ""
|
|
|
+ )
|
|
|
+ // 设置主题
|
|
|
+ config.setTopic("hcp_pad")
|
|
|
+ // 设置tag信息,此tag会附加在每条日志上
|
|
|
+ config.addTag("hcp", "hcp_pad")
|
|
|
+ // 每个缓存的日志包的大小上限,取值为1~5242880,单位为字节。默认为1024 * 1024
|
|
|
+ config.setPacketLogBytes(1024 * 1024)
|
|
|
+ // 每个缓存的日志包中包含日志数量的最大值,取值为1~4096,默认为1024
|
|
|
+ config.setPacketLogCount(1024)
|
|
|
+ // 被缓存日志的发送超时时间,如果缓存超时,则会被立即发送,单位为毫秒,默认为3000
|
|
|
+ config.setPacketTimeout(3000)
|
|
|
+ // 单个Producer Client实例可以使用的内存的上限,超出缓存时add_log接口会立即返回失败
|
|
|
+ // 默认为64 * 1024 * 1024
|
|
|
+ config.setMaxBufferLimit(64 * 1024 * 1024)
|
|
|
+ // 发送线程数,默认为1
|
|
|
+ config.setSendThreadCount(3)
|
|
|
+ //网络连接超时时间,整数,单位秒,默认为10
|
|
|
+ config.setConnectTimeoutSec(10)
|
|
|
+ //日志发送超时时间,整数,单位秒,默认为15
|
|
|
+ config.setSendTimeoutSec(10)
|
|
|
+ //flusher线程销毁最大等待时间,整数,单位秒,默认为1
|
|
|
+ config.setDestroyFlusherWaitSec(2)
|
|
|
+ //sender线程池销毁最大等待时间,整数,单位秒,默认为1
|
|
|
+ config.setDestroySenderWaitSec(2)
|
|
|
+ //数据上传时的压缩类型,默认为LZ4压缩,0 不压缩,1 LZ4压缩,默认为1
|
|
|
+ config.setCompressType(1)
|
|
|
+ //设备时间与标准时间之差,值为标准时间-设备时间,一般此种情况用户客户端设备时间不同步的场景
|
|
|
+ //整数,单位秒,默认为0;比如当前设备时间为1607064208, 标准时间为1607064308,则值设置为 1607064308 - 1607064208 = 10
|
|
|
+ config.setNtpTimeOffset(3)
|
|
|
+ //日志时间与本机时间之差,超过该大小后会根据 `drop_delay_log` 选项进行处理。
|
|
|
+ //一般此种情况只会在设置persistent的情况下出现,即设备下线后,超过几天/数月启动,发送退出前未发出的日志
|
|
|
+ //整数,单位秒,默认为7*24*3600,即7天
|
|
|
+ config.setMaxLogDelayTime(7 * 24 * 3600)
|
|
|
+ //对于超过 `max_log_delay_time` 日志的处理策略
|
|
|
+ //0 不丢弃,把日志时间修改为当前时间; 1 丢弃,默认为 1 (丢弃)
|
|
|
+ config.setDropDelayLog(0)
|
|
|
+ //是否丢弃鉴权失败的日志,0 不丢弃,1丢弃
|
|
|
+ //默认为 0,即不丢弃
|
|
|
+ config.setDropUnauthorizedLog(0)
|
|
|
+ // 是否使用主线程回调
|
|
|
+ // false: 使用主线程回调。回调会在主线程上执行,且每个 client 都有自己单独的回调。
|
|
|
+ // true: 使用 sender 线程回调。回调会在 sender 现呈上执行,每次执行回调时都会 attach 一个新的 java 线程,所有 client 共用一个回调。
|
|
|
+ // 注意:默认使用 sender 线程回调。
|
|
|
+ config.setCallbackFromSenderThread(false)
|
|
|
+ /**
|
|
|
+ * 以下为通过 LogProducerConfig 构造一个 LogProducerClient 实例
|
|
|
+ */
|
|
|
+ // callback为可选配置, 如果不需要关注日志的发送成功或失败状态, 可以不注册 callback
|
|
|
+ val callback =
|
|
|
+ LogProducerCallback { resultCode, reqId, errorMessage, logBytes, compressedBytes -> // resultCode: 状态码, 详见 LogProducerResult
|
|
|
+ // reqId: 请求Id, 已经废弃
|
|
|
+ // errorMessage: 失败信息
|
|
|
+ // logBytes: 日志原始字节数
|
|
|
+ // compressedBytes: 日志压缩字节数
|
|
|
+ val log = String.format(
|
|
|
+ "resultCode: %d, reqId: %s, errorMessage: %s, logBytes: %d, compressedBytes: %d",
|
|
|
+ resultCode,
|
|
|
+ reqId,
|
|
|
+ errorMessage,
|
|
|
+ logBytes,
|
|
|
+ compressedBytes
|
|
|
+ )
|
|
|
+ log.loge()
|
|
|
+ Log.e("wpp", log)
|
|
|
+ }
|
|
|
+ // 需要关注日志的发送成功或失败状态时, 第二个参数需要传入一个 callbak
|
|
|
+ client = LogProducerClient(config, callback)
|
|
|
+ } catch (e: LogProducerException) {
|
|
|
+ val error = "阿里云日志初始化异常: $e"
|
|
|
+ Log.e("wpp", error)
|
|
|
+ error.loge()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
protected inline fun binding(block: DB.() -> Unit): DB {
|
|
|
return binding.apply(block)
|
|
|
}
|
|
|
@@ -276,8 +371,7 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(),
|
|
|
fun showFragment(viewId: Int, f: Fragment) {
|
|
|
try {
|
|
|
val ft = supportFragmentManager.beginTransaction()
|
|
|
- if (showFragment != null)
|
|
|
- ft.hide(showFragment!!)
|
|
|
+ if (showFragment != null) ft.hide(showFragment!!)
|
|
|
if (f.isAdded) {
|
|
|
ft.show(f)
|
|
|
} else {
|
|
|
@@ -322,4 +416,21 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(),
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+ fun sendLog(log: com.aliyun.sls.android.producer.Log) {
|
|
|
+ val result = client!!.addLog(log)
|
|
|
+ Log.e("wpp", "阿里云日志上报记录" + result.toString())
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun oneLog(): com.aliyun.sls.android.producer.Log {
|
|
|
+ val log = com.aliyun.sls.android.producer.Log()
|
|
|
+ log.putContent(
|
|
|
+ "wpp",
|
|
|
+ "测试阿里云日志上报"
|
|
|
+ )
|
|
|
+ log.putContent("random", Math.random().toString())
|
|
|
+ log.putContent("content", "中文️")
|
|
|
+ log.putContent(null, "null")
|
|
|
+ return log
|
|
|
+ }
|
|
|
+
|
|
|
}
|