腾讯云结构化日志写入
allprojects {
repositories {
//...
maven { url 'https://www.jitpack.io' }
}
}
dependencies {
implementation 'com.github.dqh147258:TencentLog:1.0.7'
}
companion object {
private const val TENCENT_CLOUD_LOG_SECRET_ID = "your secret id"
private const val TENCENT_CLOUD_LOG_SECRET_KEY = "your secret key"
private const val TENCENT_CLOUD_LOG_AREA = "the area id of your tencent log server"
private const val TENCENT_CLOUD_LOG_TOPIC_ID = "your topic id"
}
TencentLogManager.init(TENCENT_CLOUD_LOG_SECRET_ID, TENCENT_CLOUD_LOG_SECRET_KEY, TENCENT_CLOUD_LOG_AREA)
val logWriter = TencentLogManager.instance.getLogWriter(TENCENT_CLOUD_LOG_TOPIC_ID)
val map = HashMap<String, String>()
map["test"] = "just for test"
logWriter.log(map) { result, message ->
if (!result) {
Log.w(TAG, "report log to tencent cloud failed, message: $message")
}
}
这里使用的protobuf库是protobuf-javalite
如果你使用的其它库(protobuf-java,protobuf-lite)则需要将其它的库排除掉,不然编译将会报错.
以protobuf-lite
为例,在app的build.gradle中添加如下配置
android {
//...
configurations {
implementation.exclude module:'protobuf-lite'
}
}
如果项目中有使用到protobuf-java
,请使用
dependencies {
implementation 'com.github.dqh147258:TencentLog:2.0.+'
}
源码是protobuf-java
分支