Android用例
添加ezlog依赖
打开项目build.gradle
文件,添加mavenCentral
仓库
buildscript {
repositories {
...
mavenCentral()
...
}
}
allprojects {
repositories {
...
mavenCentral()
...
}
}
在App层级的build.gradle
添加ezlog依赖
dependencies {
implementation "wtf.s1.ezlog:ezlog:0.2+"
}
同步gradle
在应用中初始化
override fun onCreate() {
super.onCreate()
val path = File(filesDir, "ezlog").absolutePath
val config = EZLogConfig.Builder("demo", path)
.compress(EZLog.CompressZlib)
.compressLevel(EZLog.CompressFast)
.cipher(EZLog.Aes128Gcm)
.cipherKey("a secret key!!!!".toByteArray())
.cipherNonce("unique nonce".toByteArray())
.enableTrace(BuildConfig.DEBUG)
.build()
EZLog.initWith(config)
EZLog.v("ezlog", "first blood")
EZLog.registerCallback(object : Callback {
override fun onLogsFetchSuccess(
logName: String?,
date: String?,
logs: Array<out String>?
) {
Log.i("ezlog", "$logName $date ${logs.contentToString()}")
logs?.let {
logs.getOrNull(0)?.let { log ->
Log.i("ezlog", "check file exists ${File(log).exists()}")
}
}
}
override fun onLogsFetchFail(logName: String?, date: String?, err: String?) {
Log.i("ezlog", "$logName $date $err")
}
})
}