Commit 3507c44d by 刘鹏

feat: 加入阿里云日志,封装工具类

parent 6f71c519
......@@ -33,7 +33,7 @@ ext {
//-------------- 功能组件 --------------
//第一步
"ydl-platform" : "0.0.39.89",
"ydl-platform" : "0.0.39.95",
//第二步 若干
"ydl-webview" : "0.0.38.36",
......@@ -115,7 +115,7 @@ ext {
//-------------- 功能组件 --------------
//第一步
"ydl-platform" : "0.0.39.89",
"ydl-platform" : "0.0.39.95",
//第二步 若干
"ydl-webview" : "0.0.38.36",
......
......@@ -72,10 +72,12 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api 'com.aliyun.openservices:aliyun-log-android-sdk:2.5.13'
//====================YDL Repository====================
// api rootProject.ext.dependencies["ydl-pushagent"]
// api rootProject.ext.dependencies["ydl-hnet"]
api (rootProject.ext.dependencies["ydl-notracepoint"]){
api(rootProject.ext.dependencies["ydl-notracepoint"]) {
transitive = true
exclude group: 'com.google.code.gson', module: 'gson'
exclude group: 'com.squareup.okhttp3', module: 'okhttp3'
......
package com.ydl.ydlcommon.utils.log
object AliYunLogConfig {
/**接口*/
const val API = "API"
/**声网*/
const val AGORA = "Agora"
/**登录*/
const val LOGIN = "Login"
/**WebView*/
const val WEB = "Web"
/**支付*/
const val PAY = "Pay"
/**其他*/
const val OTHER = "Other"
}
\ No newline at end of file
package com.ydl.ydlcommon.utils.log
import android.util.Log
import com.aliyun.sls.android.producer.*
class AliYunLogHelper {
companion object {
var mConfig: LogProducerConfig? = null
var mClient: LogProducerClient? = null
fun getInstance(): AliYunLogHelper {
return Holder.INSTANCE
}
}
constructor() {
val endpoint = "cn-hangzhou.log.aliyuncs.com"
val project = "ydl-app-log"
val logstore = "ydl-app-log"
val accesskeyid = "LTAI5tH6WGqWUqzo4u5GfrCS"
val accesskeysecret = "uzccm79mr9d4rIsABu3xwfbdUdaeWT"
try {
mConfig = LogProducerConfig(endpoint, project, logstore, accesskeyid, accesskeysecret)
mClient = LogProducerClient(mConfig)
} catch (e: LogProducerException) {
e.printStackTrace()
}
}
private object Holder {
val INSTANCE = AliYunLogHelper()
}
/**
*
* @param key AliYunLogConfig 接口、登录、声网、WebView、支付、其他
* @param value 具体的状态值
* */
fun sendLog(key: String, value: String) {
val log = Log()
log.putContent(key, value)
if (mClient != null) {
val res: LogProducerResult = mClient!!.addLog(log)
Log.d("LogProducerResult", String.format("%s %s", res, res.isLogProducerResultOk))
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment